Actually I am facing Out of Memory error in my app.:( the problem is that I have been using number of activities in my app and now at this point I can't move to another approach..:( So after flipping 27 or 29 activties i get OOM error on 30 activity on setContentView(). In my all XML files I have been using AbsoluteLayout setting background image with a main page for each Layout. And in every layout I have been setting 4 to 5 buttons with background having image. now every button is set with an image with sound.
-
Try solving your problem by [reading this](http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object) – AnilPatel Apr 24 '13 at 12:56
2 Answers
I suggest to use the system.gc()
and finish();
every time jump the another activity it's clear your used resources and free it. ok then does not occurred the out of memory error in your app. it's work try this.
Best of Luck
Use this link and get better solution
What Android tools and methods work best to find memory/resource leaks?

- 1
- 1

- 2,929
- 5
- 32
- 58
-
There should never be a need to call system.gc(). It's quite possible that he's holding onto references of the activities he's creating and thus Android can't remove them from memory. – ajacian81 Sep 28 '12 at 11:17
-
ok dear then use this link it`s very helpful to me i hope it help to you http://stackoverflow.com/questions/1147172/what-android-tools-and-methods-work-best-to-find-memory-resource-leaks/1147344#1147344 – Zala Janaksinh Sep 28 '12 at 11:24
-
-
I've been butting up against this issue on a Gingerbread (2.3.7) device with not a great deal of RAM (HTC Wildfire). After rotating the device a few times, the app crashes with:
E/AndroidRuntime( 4805): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
E/AndroidRuntime( 4805): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/AndroidRuntime( 4805): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
E/AndroidRuntime( 4805): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
E/AndroidRuntime( 4805): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
E/AndroidRuntime( 4805): at android.content.res.Resources.loadDrawable(Resources.java:1785)
E/AndroidRuntime( 4805): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
E/AndroidRuntime( 4805): at android.widget.ImageView.<init>(ImageView.java:118)
E/AndroidRuntime( 4805): at android.widget.ImageView.<init>(ImageView.java:108)
E/AndroidRuntime( 4805): ... 26 more
The layout that's rotating is pretty simple, a RelativeLayout
with a few ImageView
children, one of which has a relatively large (filesize) image as the background for part of the screen.
I tried implementing @AndroidUsers's solution but that did not correct my issue. With a bit more work I found that the ImageView I was holding the background image in wasn't releasing its memory properly so I added another check to the unbindDrawables method. I also bundled in the system.gc() call via an extra parameter so it can't be missed:
public static void unbindDrawables(View view, boolean runGC) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ImageView) {
((ImageView) view).setImageBitmap(null);
((ImageView) view).setImageDrawable(null);
}
else if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i), false);
}
((ViewGroup) view).removeAllViews();
}
if(runGC) {
System.gc();
}
}
In my testing it doesn't seem to matter which of the Bitmap or Drawable you set to null, but I figured both couldn't hurt.

- 1,057
- 11
- 19