Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.

[fix] leaking the last request object after request queue is drained #64

Merged
merged 1 commit into from Jun 26, 2015

Commits on Jun 25, 2015

  1. [fix] leaking the last request object after request queue is drained

    description:
      this leak can be detected by LeakCanary, see
    
      D/LeakCanary﹕ In io.github.pandacast:1.1:2.
      D/LeakCanary﹕ * io.github.pandacast.MainActivity has leaked:
      D/LeakCanary﹕ * GC ROOT thread
      com.android.volley.NetworkDispatcher.<Java Local> (named 'Thread-5690')
      D/LeakCanary﹕ * references
      io.github.pandacast.model.RestClient$LiveListRequest.mListener
      D/LeakCanary﹕ * references
      io.github.pandacast.LiveListFragment$LiveListAdapter.mContext
      D/LeakCanary﹕ * leaks io.github.pandacast.MainActivity instance
    
    root cause:
      In NetworkDispatcher.run(), the local variable `request` hold
      the last Request object. If there is no more Request object in
      `mQueue`, `request = mQueue.take();` in line 90 would **block**
      until new Request object enqueue, which cause the leak of last
      Request object.
    
      In common pracice, Request has strong reference to Listener and
      Listener is either implmented by Activity or referenced by
      Activity as instance of inner class which implement Listener.
      Thus cause leaking the whole Activity instance.
    
    how to fix:
      set request to **null** before `request = mQueue.take();`
    bshao committed Jun 25, 2015
    Configuration menu
    Copy the full SHA
    8e75d19 View commit details
    Browse the repository at this point in the history