title: Out of memory error on Android
body: <p>I am developing an android game application where I have about 15 screens. When I continuously play, I get an out of memory error problem randomly, sometimes in the 15th screen, and sometimes in the 12th screen or so.</p>
  
  <p>Also, check out the xml below, of one the screens.</p>
  
  <pre><code>      &lt;?xml version="1.0" encoding="UTF-8"?&gt;
         &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
             android:id="@+id/MainFrame"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent" &gt;
  
     &lt;RelativeLayout
         android:id="@+id/mainlayout"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:background="@drawable/woodenbg1" &gt;
  
         &lt;Chronometer
          android:id="@+id/chronometer"
          android:layout_width="0dp"
          android:layout_height="0dp"
          android:textSize="20sp"
          android:textStyle="bold"
          android:typeface="sans"
          android:visibility="gone" /&gt;
  
      &lt;ImageView
          android:id="@+id/imageline"
          android:layout_width="10000dp"
          android:layout_height="wrap_content"
          android:layout_marginTop="105dp"
          android:src="@drawable/lineblackfornormal" /&gt;
  
      &lt;ImageView
          android:id="@+id/imageviewunderalphac"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="350dp"
          android:src="@drawable/whitec" /&gt;
  
      &lt;ImageView
          android:id="@+id/backgroundofalphab"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="35dp"
          android:src="@drawable/backgroundfordragimages"
          android:visibility="invisible" /&gt;
  
        &lt;ImageView
            android:id="@+id/backgroundofalphaa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="35dp"
            android:src="@drawable/backgroundfordragimages"
            android:visibility="invisible" /&gt;
  
         &lt;ImageView
             android:id="@+id/backgroundofalphac"
             android:layout_width="100dp"
             android:layout_height="wrap_content"
             android:layout_alignParentRight="true"
             android:layout_marginTop="33dp"
             android:src="@drawable/backgroundfordragimages"
             android:visibility="invisible" /&gt;
  
         &lt;ImageView
            android:id="@+id/imageviewunderleftalphab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="250dp"
            android:layout_marginLeft="15dp"
            android:src="@drawable/whiteb" /&gt;
  
        &lt;ImageView
            android:id="@+id/imageviewunderrightalphaa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="250dp"
            android:layout_marginRight="10dp"
            android:src="@drawable/whitea" /&gt;
  
        &lt;ImageView
            android:id="@+id/imageviewabovealphab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="35dp"
            android:src="@drawable/colouredb" /&gt;
  
         &lt;ImageView
            android:id="@+id/imageviewabovealphaa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="35dp"
            android:src="@drawable/coloureda" /&gt;
  
         &lt;ImageView
            android:id="@+id/imageviewabovealphac"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/backgroundofalphac"
            android:layout_marginTop="33dp"
            android:src="@drawable/colouredc" /&gt;
         &lt;/RelativeLayout&gt;
  
       &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>Logcat</p>
  
  <pre><code>  05-16 12:22:18.989: E/GraphicsJNI(6745): VM won't let us allocate 2225664 bytes
    05-16 12:22:18.999: E/AndroidRuntime(6745): FATAL EXCEPTION: main
    05-16 12:22:18.999: E/AndroidRuntime(6745): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.graphics.Bitmap.nativeCreate(Native Method)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.content.res.Resources.loadDrawable(Resources.java:1709)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.content.res.Resources.getDrawable(Resources.java:581)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.view.View.setBackgroundResource(View.java:7533)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at com.ssn.myapp.NumbersLevel3.onCreate(NumbersLevel3.java:173)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2832)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.app.ActivityThread.access$1600(ActivityThread.java:117)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.os.Handler.dispatchMessage(Handler.java:99)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.os.Looper.loop(Looper.java:130)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at android.app.ActivityThread.main(ActivityThread.java:3683)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at java.lang.reflect.Method.invokeNative(Native Method)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at java.lang.reflect.Method.invoke(Method.java:507)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    05-16 12:22:18.999: E/AndroidRuntime(6745):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>