I appreciate your response.

I'm holding open max 10 cursors at a time. I'll probably implement
onLowMemory() to clear the cache should things get nasty.

I only use one ListView.

My point was that there are cases where you might use a cursor pool
(really, I mean cache) where that class does not know how the cursors
are being used. It may happen to close a cursor that is currently used
by a ListView. Of course, you can make the cursor pool so that its
stopped from closing "active" cursors.

Out of interest, the reason I observed this exception is because I
incorrectly hadnt set the accessOrder of the pool's LinkedHashMap to
true.

Fixing this should solve the problem but I maintain its still odd (and
a potential bug many devs would miss) that calling Cursor.close()
could lead to such an exception. *ducks*

On Apr 9, 8:42 pm, Mark Murphy <[email protected]> wrote:
> westmeadboy wrote:
> > Caching search results. The searches happen as the user types so when
> > a user hits backspace its nice if the results are shown instantly
> > rather than requerying.
>
> Bear in mind that Cursors hold a copy of the query result set. The more
> Cursors you hold onto, the more memory you consume.
>
> Going back to your original problem, I don't see how you're getting into
> trouble. You have N Cursors. One of these Cursors is in a ListView. You
> know which one of these Cursors is in a ListView (your statement "so do
> not know how a given cursor is being used" is false). The other Cursors
> are, hopefully, not in a ListView. So you have:
>
> -- 1 ListView
> -- 1 CursorAdapter
> -- N Cursors
>
> I assume you are not calling close() on the Cursor that is in the
> CursorAdapter, as the user is kinda looking at it. None of the other
> Cursors should be connected to the UI, and so you should not get that
> exception.
>
> If you are getting the exception on a Cursor that is not held by any
> CursorAdapter/ListView, that might be a bug in Android, or perhaps some
> other step you need to do to completely detach the Cursor from the
> CursorAdapter when you swap in another Cursor.
>
> If you actually have N ListViews and N CursorAdapters, please
> reconsider. That's gobs more memory you're taking up and, among other
> things, leaves you open for this error.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> _Android Programming Tutorials_ Version 2.0 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to