Skip to content

Commit 034de6b

Browse files
author
Romain Guy
committed
Plug memory leak that happens when reusing display lists
Bug #7195815 We did not reclaim resources when reusing an existing DisplayList to record a new empty list of commands. This would lead to various memory leaks: bitmaps, paints, paths, matrices, etc. This is not a common case but some apps run into this situation, such as Launcher. Change-Id: I2eb14ac86a212123f8edbe42b70a7c1c51fa4145
1 parent 6ed9e43 commit 034de6b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

libs/hwui/DisplayListRenderer.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ void DisplayList::destroyDisplayListDeferred(DisplayList* displayList) {
143143

144144
void DisplayList::clearResources() {
145145
sk_free((void*) mReader.base());
146+
mReader.setMemory(NULL, 0);
146147

147148
delete mTransformMatrix;
148149
delete mTransformCamera;
@@ -216,19 +217,19 @@ void DisplayList::clearResources() {
216217

217218
void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) {
218219
const SkWriter32& writer = recorder.writeStream();
219-
init();
220-
221-
if (writer.size() == 0) {
222-
mFunctorCount = 0;
223-
return;
224-
}
225220

226221
if (reusing) {
227222
// re-using display list - clear out previous allocations
228223
clearResources();
229224
}
225+
226+
init();
230227
initProperties();
231228

229+
if (writer.size() == 0) {
230+
return;
231+
}
232+
232233
mSize = writer.size();
233234
void* buffer = sk_malloc_throw(mSize);
234235
writer.flatten(buffer);
@@ -301,6 +302,7 @@ void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorde
301302
void DisplayList::init() {
302303
mSize = 0;
303304
mIsRenderable = true;
305+
mFunctorCount = 0;
304306
}
305307

306308
size_t DisplayList::getSize() {

0 commit comments

Comments
 (0)