-
Notifications
You must be signed in to change notification settings - Fork 754
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
Leaking last request in CacheDispatcher #19
Comments
Thanks; it seems legitimate. I'm not completely a fan of the above fix (mostly because it adds a needless catch-all-exception block). AFAICT this should be very simple to fix: just add a request = null before the request = mCacheQueue.take() as the latter is a blocking call. Pull requests welcome :) |
Looking more closely at the screenshot, it seems to indicate that what's holding onto the activity isn't the local variable in dispatcher loop (or at least, isn't just that), but is mCacheQueue, the queue itself. queue is a member variable of PriorityBlockingQueue which contains the contents. If that's the leak, then I don't see how this kind of fix would resolve it. Are you testing on a device which uses Dalvik or one which uses ART? If it's the latter, then none of the analysis from that blog post should apply as it states that they never saw the issue with ART (and the stack trace from the screenshot would seem to bear that out). It seems like a more fundamental issue to me; if you're using a heavy object (i.e. Activity) as your response listener, and that object goes away while the request is in flight, then there are a number of Volley internals like this one that will retain a reference to the request, even if you're a well-behaved client that calls cancel() on the request when that heavy object is destroyed. See also #15 (comment). I think this is going to be a more involved change if we want to fix it. We could look into using WeakReference anywhere that we hold onto an object that might be/hold a Fragment/Activity. In your particular case it seems like you've set the request tag (mTag) to a fragment instance; have you tried more cleanly separating your Request objects from any Fragments/Activities and seeing if that addresses your particular leak? |
I think you are correct. The problem I see is related to the queue it self. I found this issue PriorityBlockingQueue keeps hard reference to last removed element which has some example code for printing the queue after the last element has be taken. On a 4.2.2 device (Galaxy core), the last element does not seem to be nulled out, but it is on later versions of Android (tested 6.0 and 7.0). I'm not sure how to confirm that this bug exists in Android source code it self. |
Will close this, as I'm not able to provider more information or a solution at this time. |
FYI, we got a similar report in #114 with a sample app, and it seems like newer versions of Android have reintroduced the issue that was previously resolved with ART. In summary:
|
Android Studio reported a leaked
Activity
that I tracked down toCacheDispatcher
keeping a reference to a request:The issue was fixed in now deprecated
mcxiaoke/android-volley
repository:leaking the last request object in CacheDispatcher
And the reson for the leak is explained in:
A small leak will sink a great ship
The text was updated successfully, but these errors were encountered: