diff --git a/src/main/java/com/android/volley/NetworkDispatcher.java b/src/main/java/com/android/volley/NetworkDispatcher.java index 1775b186..65ed6634 100644 --- a/src/main/java/com/android/volley/NetworkDispatcher.java +++ b/src/main/java/com/android/volley/NetworkDispatcher.java @@ -83,10 +83,14 @@ private void addTrafficStatsTag(Request request) { public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); Request request; + NetworkResponse networkResponse; + Response response; while (true) { long startTimeMs = SystemClock.elapsedRealtime(); - // release previous request object to avoid leaking request object when mQueue is drained. + // release previous tmp objects to avoid leaking these objects when mQueue is drained. request = null; + networkResponse = null; + response = null; try { // Take a request from the queue. request = mQueue.take(); @@ -111,7 +115,7 @@ public void run() { addTrafficStatsTag(request); // Perform the network request. - NetworkResponse networkResponse = mNetwork.performRequest(request); + networkResponse = mNetwork.performRequest(request); request.addMarker("network-http-complete"); // If the server returned 304 AND we delivered a response already, @@ -122,7 +126,7 @@ public void run() { } // Parse the response here on the worker thread. - Response response = request.parseNetworkResponse(networkResponse); + response = request.parseNetworkResponse(networkResponse); request.addMarker("network-parse-complete"); // Write to cache if applicable.