7

Is anyone knows how to Release bitmaps from android.view.GLES20DisplayList. And why it keeps them alive even if you clean, let's say, ImageView manually? Or maybe there is a way to disable GLES20DisplayList, tried to use android:hardwareAccelerated="false" in AndroidManifest, still no luck.

Looks like affected only in 4.2(1)

update: looks like you can't disable hardware acceleration on 4.2.1 (bug?)

simple test:

Android manifest:
application ... android:hardwareAccelerated="false"

System.out.println("isHardwareAccelerated: " + mListView.isHardwareAccelerated());
mListView.setLayerType(LAYER_TYPE_SOFTWARE, null);
System.out.println("isHardwareAccelerated: " + mListView.isHardwareAccelerated());

result:

12-06 17:15:27.129: I/System.out(30752): isHardwareAccelerated: true
12-06 17:15:27.129: I/System.out(30752): isHardwareAccelerated: true
vovkab
  • 1,292
  • 11
  • 17

2 Answers2

3

This seems to be a memory leak in 4.2. Looks like this fix is intended against it: https://android.googlesource.com/platform/frameworks/base/+/034de6b1ec561797a2422314e6ef03e3cd3e08e0

I disabled hardware acceleration in the manifest for 4.2 for the activity where I encountered this problem, this helped with android.view.GLES20DisplayList memory holding.

In the manifest for activity: android:hardwareAccelerated="@bool/gpu_enabled"

In values.xml for v17:

<bool name="gpu_enabled">false</bool>   

In default values.xml, I set it to true.

Yulia Rogovaya
  • 924
  • 1
  • 8
  • 26
  • 1
    This one happens because they keep bitmaps until view is removed. Here is comment from GLES20DisplayList: /* These lists ensure that any Bitmaps and DisplayLists recorded by a DisplayList are kept alive as long as the DisplayList is alive. The Bitmap and DisplayList lists are populated by the GLES20RecordingCanvas during appropriate drawing calls and are cleared at the start of a new drawing frame or when the view is detached from the window. */ Basically you need detach view to be able to recycle bitmap/drawable. – vovkab Jan 15 '13 at 00:02
  • I removed the views in onStop, still the memory was being held. (only on 4.2) – Yulia Rogovaya Jan 17 '13 at 12:04
  • What memory analyzer shows? Maybe someone else is keeping reference or context is leaked? Try to clean bitmaps completly from ImageViews and then detach view. – vovkab Jan 17 '13 at 23:09
1

I recently did an in-depth memory analysis regarding this issue. As Yulia pointed out above, disabling hardware acceleration would do the trick in general. Alternatively, you can set the ImageView’s Drawable to null, recycle the bitmap, or detach the ImageView as you pointed out.

However, depending on the API version, the bitmap memory may or may not be released from GLES20DisplayList. I discussed these different behaviors and possible solutions in-depth on my blog post – Android Bitmap Memory Analysis, but the quick solution would be to disable hardware acceleration.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
hiBrianLee
  • 1,847
  • 16
  • 19