Merge "Workaround an interpreter behavior to fix leak" into oc-dev
am: 745c6e02c6
Change-Id: I487fb7438edb7697a65e5abc695f32332f0567b1
This commit is contained in:
@@ -161,6 +161,31 @@ class BackgroundTaskLoader implements Runnable {
|
|||||||
// If we've stopped the loader, then fall through to the above logic to wait on
|
// If we've stopped the loader, then fall through to the above logic to wait on
|
||||||
// the load thread
|
// the load thread
|
||||||
if (ssp != null) {
|
if (ssp != null) {
|
||||||
|
processLoadQueueItem(ssp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are no other items in the list, then just wait until something is added
|
||||||
|
if (!mCancelled && mLoadQueue.isEmpty()) {
|
||||||
|
synchronized(mLoadQueue) {
|
||||||
|
try {
|
||||||
|
mWaitingOnLoadQueue = true;
|
||||||
|
mLoadQueue.wait();
|
||||||
|
mWaitingOnLoadQueue = false;
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
ie.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This needs to be in a separate method to work around an surprising interpreter behavior:
|
||||||
|
* The register will keep the local reference to cachedThumbnailData even if it falls out of
|
||||||
|
* scope. Putting it into a method fixes this issue.
|
||||||
|
*/
|
||||||
|
private void processLoadQueueItem(SystemServicesProxy ssp) {
|
||||||
// Load the next item from the queue
|
// Load the next item from the queue
|
||||||
final Task t = mLoadQueue.nextTask();
|
final Task t = mLoadQueue.nextTask();
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
@@ -190,7 +215,7 @@ class BackgroundTaskLoader implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (DEBUG) Log.d(TAG, "Loading thumbnail: " + t.key);
|
if (DEBUG) Log.d(TAG, "Loading thumbnail: " + t.key);
|
||||||
ThumbnailData cachedThumbnailData = ssp.getTaskThumbnail(t.key.id,
|
final ThumbnailData cachedThumbnailData = ssp.getTaskThumbnail(t.key.id,
|
||||||
true /* reducedResolution */);
|
true /* reducedResolution */);
|
||||||
|
|
||||||
if (cachedThumbnailData.thumbnail == null) {
|
if (cachedThumbnailData.thumbnail == null) {
|
||||||
@@ -199,26 +224,9 @@ class BackgroundTaskLoader implements Runnable {
|
|||||||
|
|
||||||
if (!mCancelled) {
|
if (!mCancelled) {
|
||||||
// Notify that the task data has changed
|
// Notify that the task data has changed
|
||||||
final Drawable newIcon = cachedIcon;
|
final Drawable finalIcon = cachedIcon;
|
||||||
final ThumbnailData newThumbnailData = cachedThumbnailData;
|
|
||||||
mMainThreadHandler.post(
|
mMainThreadHandler.post(
|
||||||
() -> t.notifyTaskDataLoaded(newThumbnailData, newIcon));
|
() -> t.notifyTaskDataLoaded(cachedThumbnailData, finalIcon));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there are no other items in the list, then just wait until something is added
|
|
||||||
if (!mCancelled && mLoadQueue.isEmpty()) {
|
|
||||||
synchronized(mLoadQueue) {
|
|
||||||
try {
|
|
||||||
mWaitingOnLoadQueue = true;
|
|
||||||
mLoadQueue.wait();
|
|
||||||
mWaitingOnLoadQueue = false;
|
|
||||||
} catch (InterruptedException ie) {
|
|
||||||
ie.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user