Skip to content

Commit 38c2ece

Browse files
author
Romain Guy
committed
Clear bitmap references from display lists as early as possible
Bug #6555840 Apps like Google+ with large bitmaps displayed in listivews could run into memory issues because of these references. Change-Id: I39486bda13ce00c5a3b6481139ad54547506a8b4
1 parent 393a52c commit 38c2ece

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

core/java/android/view/DisplayList.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ public abstract class DisplayList {
8282
*/
8383
public abstract void invalidate();
8484

85+
/**
86+
* Clears additional resources held onto by this display list. You should
87+
* only invoke this method after {@link #invalidate()}.
88+
*/
89+
public abstract void clear();
90+
8591
/**
8692
* Returns whether the display list is currently usable. If this returns false,
8793
* the display list should be re-recorded prior to replaying it.

core/java/android/view/GLES20DisplayList.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ public void invalidate() {
7171
mValid = false;
7272
}
7373

74+
@Override
75+
public void clear() {
76+
if (!mValid) {
77+
mBitmaps.clear();
78+
}
79+
}
80+
7481
@Override
7582
public boolean isValid() {
7683
return mValid;
@@ -343,7 +350,6 @@ private static native void nSetLeftTopRightBottom(int displayList, int left, int
343350
private static native void nSetPivotX(int displayList, float pivotX);
344351
private static native void nSetCaching(int displayList, boolean caching);
345352
private static native void nSetClipChildren(int displayList, boolean clipChildren);
346-
private static native void nSetApplicationScale(int displayList, float scale);
347353
private static native void nSetAlpha(int displayList, float alpha);
348354
private static native void nSetHasOverlappingRendering(int displayList,
349355
boolean hasOverlappingRendering);

core/java/android/view/View.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6800,6 +6800,8 @@ public TextSegmentIterator getIteratorForGranularity(int granularity) {
68006800
*/
68016801
public void dispatchStartTemporaryDetach() {
68026802
clearAccessibilityFocus();
6803+
clearDisplayList();
6804+
68036805
onStartTemporaryDetach();
68046806
}
68056807

@@ -11455,10 +11457,8 @@ protected void onDetachedFromWindow() {
1145511457
}
1145611458
mAttachInfo.mViewRootImpl.cancelInvalidate(this);
1145711459
} else {
11458-
if (mDisplayList != null) {
11459-
// Should never happen
11460-
mDisplayList.invalidate();
11461-
}
11460+
// Should never happen
11461+
clearDisplayList();
1146211462
}
1146311463

1146411464
mCurrentAnimation = null;
@@ -12236,6 +12236,13 @@ public DisplayList getDisplayList() {
1223612236
return mDisplayList;
1223712237
}
1223812238

12239+
private void clearDisplayList() {
12240+
if (mDisplayList != null) {
12241+
mDisplayList.invalidate();
12242+
mDisplayList.clear();
12243+
}
12244+
}
12245+
1223912246
/**
1224012247
* <p>Calling this method is equivalent to calling <code>getDrawingCache(false)</code>.</p>
1224112248
*

core/java/android/view/ViewRootImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,9 @@ void invalidateDisplayLists() {
23352335
final int count = displayLists.size();
23362336

23372337
for (int i = 0; i < count; i++) {
2338-
displayLists.get(i).invalidate();
2338+
final DisplayList displayList = displayLists.get(i);
2339+
displayList.invalidate();
2340+
displayList.clear();
23392341
}
23402342

23412343
displayLists.clear();

0 commit comments

Comments
 (0)