0

The code on the CacheDispatcher is as below. And focus on that release previous request object to avoid leaking request object when mQueue is drained. I do not know why. Can anyone tell me the reason? Thanks in advance.

java
Request<?> request;
while (true) {
    // release previous request object to avoid leaking request object when mQueue is drained.
    request = null;
    try {
        // Take a request from the queue.
        request = mCacheQueue.take();
    } catch (InterruptedException e) {
        // We may have been interrupted because it was time to quit.
        if (mQuit) {
            return;
        }
        continue;
    }
}
Andrei Herford
  • 17,570
  • 19
  • 91
  • 225
aheadlcx
  • 63
  • 5

1 Answers1

1

request = mCacheQueue.take(); is a blocking call so when the queue is empty(drained) we will still keep reference of the old request while waiting if we didn't do request = null;

this however is not the best way to achieve this behavior and it was changed in the new Volley code to :

while (true) {
            try {
                // Get a request from the cache triage queue, blocking until
                // at least one is available.
                final Request<?> request = mCacheQueue.take();
kalin
  • 3,546
  • 2
  • 25
  • 31