0

CacheDispatcher 上的代码如下。并专注于释放先前的请求对象,以避免在 mQueue 耗尽时泄漏请求对象。我不知道为什么。谁能告诉我原因?提前致谢。

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;
    }
}
4

1 回答 1

1

request = mCacheQueue.take();是一个阻塞调用,所以当队列为空(耗尽)时,如果我们没有这样做,我们仍然会在等待时保持对旧请求的引用request = null;

然而,这不是实现此行为的最佳方式,它在新的 Volley 代码中更改为:

while (true) {
            try {
                // Get a request from the cache triage queue, blocking until
                // at least one is available.
                final Request<?> request = mCacheQueue.take();
于 2016-04-28T20:35:32.737 回答