## Massive Memory Leak with Background Image

_Submitted by a community member on 2012-01-24 03:45 UTC_

Bitmap images attached as background drawables are never released.

In order to re-create the problem just create a default Mono for Android project and add the XML attribute

android:background="@drawable/wallpaper"

to the outer LinearLayout. Also add a wallpaper.png image (make it large to quickly see the problem, e.g. 1280x1024 pixels) to the resources drawable folder. Then start the application.

When turning the orientation of the device (portrait/landscape) the activity is re-created by Android with every turn. Turning the device several times (about 7 times with a 1280x1024 image) causes an exception and terminates the App because we are already running out of memory.

I even trimmed down the default application to just

namespace MonoAndroidApplication2
{
```
        [Activity(Label = "MonoAndroidApplication2", MainLauncher = true)]
        public class Activity1 : Activity
        {
                protected override void OnCreate(Bundle bundle)
                {
                        base.OnCreate(bundle);
                        SetContentView(Resource.Layout.Main);
                }
        }
```

}

and still, at least the memory of the background image is leaked with every turn of the device.

To verify that the problem is with Mono and not with Android itself, I also created a Java Android default application and made the very same changes to it, using the very same image. Needless to say, the real Android application does never exhaust its memory.

* * *

_Reference: <https://bugzilla.xamarin.com/show_bug.cgi?id=3024>_