Androud Bitmap Resource Memory Leaks (Bug!)

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Androud Bitmap Resource Memory Leaks (Bug!)

Postby VIDEN » Wed Jul 22, 2009 4:23 pm

It seems to me like Android has a Memory Leak Bug with Background Images loaded from XML resources.

Lets put up the following setup: A clean new Android 1.5 SDK Project with only one Activity containing this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class Sandbox extends Activity {
  3.  
  4.     /** Called when the activity is first created. */
  5.  
  6.     @Override
  7.  
  8.     public void onCreate(Bundle savedInstanceState) {
  9.  
  10.         super.onCreate(savedInstanceState);
  11.  
  12.         setContentView(R.layout.main);
  13.  
  14.     }
  15.  
  16. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



And an XML layout "main" just containing this:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:orientation="vertical"    
  6.  
  7.    android:background="@drawable/1mb_png_image"
  8.  
  9.    android:layout_width="fill_parent"
  10.  
  11.    android:layout_height="fill_parent"
  12.  
  13.    />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


As seen I am using a 1mb Image resource for my layouts background.
If you start the App, turn the Orientation two times it will crash with the following error:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
cause by the Inflation of the XML file.

The only way I can stop the app from crashing.. and leaking memory is getting the background drawable, setting the callback of it to null AND then setting the Layouts backgrounddrawable to null...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. getBackground().setCallback(null);
  2.  
  3.                 setBackgroundDrawable(null);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



This really looks like a Bug to me... and a pretty bad Bug!!

Anny comments? Am I missing something?

Greets David
VIDEN
Developer
Developer
 
Posts: 32
Joined: Tue May 12, 2009 9:39 am
Location: Germany

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests