-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HandlerThread from android.widget.Filter seems to leak the filter which leaks the adapter #10
Comments
Can It be a false positive? I can't even find a thread named "Filter" in the heap dump. Edit: The thread is definitely stopped here. I think this is a false positive. |
As you pointed out, the thread is definitely getting stopped. However, the FINISH_TOKEN message is always sent 3 seconds after the last FILTER_TOKEN message is received. Do you call
A possible explanation might be that you still call Filter.filter() after the fragment / activity has been destroyed. |
In any case, this will never lead to a real leak, right? If true, I'd like to exclude this somehow from the leak detection. Is this possible? |
In other words: when / how do you call Filter.filter() ? You could investigate this by opening the heap dump and checking what messages you have in MessageQueue.mMessages (it's a linked list) for that specific handler thread. |
I call it in a TextWatcher in the same fragment. Like I said, I can't even find the thread in the heap dump. I'm guessing that in the time that the dump takes to be created the thread is already collected. |
The thread exists in the heap dump, otherwise the leak trace would not show it :) . Look for instances of HandlerThread, and then look for one with the field "name" set to "Filter" This could be a real leak. If you never stop calling Filter.filter() on that instance, then the thread will never stop, the Filter won't be GCed, and the destroyed activity won't be GCed as well. If we find that this is a real general android leak, we can add it to the library list of excluded references. However, if it's not and you still want to ignore it, you can but it's going to be more manual. You need to create your own version of HeapAnalyzerService, and replace createAppDefaults() with something that adds excluded refs to it. Then create your own version of ServiceHeapDumpListener that starts that service, and create the RefWatcher with it. We might consider changing the API to allow for easier customization of the ignored refs, but in the meantime you can still roll your own :) . |
It'd be nice to get to the bottom of this. It seems that Filter should have a |
Also, there is a way for you to prevent this from happening: set the StationSearchListAdapter$StationSearchFilter.stationSearchListAdapter field to null when the list view is detached. |
For starters I created issue #12 to track the exclude API. You're right in that the HandlerThread is present in the heap dump. However it is really gone in a dump I manually created moments later. I think this is really just a false positive. |
I got a couple of similar reports like this (real device)
or this (Genymotion)
As far as I can tell, the root issue is the leak of
StationSearchFilter
which holds a reference to the adapter which in turn leaks all kinds of stuff.Now, I can't figur out what exactly is causing the leak. It seems the HandlerThread that is started in Filter.filter isn't properly closed and therefore leaks a message.
The text was updated successfully, but these errors were encountered: