0

i developed one application, where i have several activities. Each activity separate into layout , left side layout contains frame by frame animation of a particular image and right side layout contains runtime canvas view, when i complete the task and move to next activity it get error OutofMemoryError.... Sometimes it happens while moving from first activity to second activity or it also get error when it passing thirdactivity to fourth activity.(bec sometimes it does not cause while moving from moving first to second and second to third). Getting error Like this:

08-11 08:24:11.176: E/AndroidRuntime(859): java.lang.OutOfMemoryError
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:503)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:356)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:800)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.content.res.Resources.loadDrawable(Resources.java:2105)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.content.res.Resources.getDrawable(Resources.java:695)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:282)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:901)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.content.res.Resources.loadDrawable(Resources.java:2087)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.content.res.Resources.getDrawable(Resources.java:695)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.view.View.setBackgroundResource(View.java:14758)
08-11 08:24:11.176: E/AndroidRuntime(859):  at com.mypack.capitalAlphabets.ActivityD.onCreate(ActivityD.java:28)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.app.Activity.performCreate(Activity.java:5133)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.os.Looper.loop(Looper.java:137)
08-11 08:24:11.176: E/AndroidRuntime(859):  at android.app.ActivityThread.main(ActivityThread.java:5103)
08-11 08:24:11.176: E/AndroidRuntime(859):  at java.lang.reflect.Method.invokeNative(Native Method)
08-11 08:24:11.176: E/AndroidRuntime(859):  at java.lang.reflect.Method.invoke(Method.java:525)
08-11 08:24:11.176: E/AndroidRuntime(859):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-11 08:24:11.176: E/AndroidRuntime(859):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-11 08:24:11.176: E/AndroidRuntime(859):  at dalvik.system.NativeStart.main(Native Method)
08-11 08:29:11.335: I/Process(859): Sending signal. PID: 859 SIG: 9
08-11 08:29:13.265: D/gralloc_goldfish(904): Emulator without GPU emulation detected.
kalyan pvs
  • 14,486
  • 4
  • 41
  • 59
Ashok
  • 839
  • 10
  • 21

4 Answers4

0

You should handle Bitmap recycling. Based on the exception, it looks like you are filling the memory over and over again with heavy Bitmaps. But I can't tell more without seeing the code.

Look here: http://developer.android.com/training/displaying-bitmaps/index.html

Deimos
  • 1,083
  • 1
  • 10
  • 15
0

If i am right, you are viewing image in your activity (most probably multiple images).. The size of your image is very big that is why it is throwing outOfMemoryError. You should control the size and properties of your image according to the size and as you need..You can also search for method to recycle memory.. you can also use onLowMemory method and stop from crashing application and show some error dialog.. but yeah control the size and property of your image

user98239820
  • 1,411
  • 2
  • 16
  • 30
0

Probably the images which you are using are of very large size..reduce the resolution and see if you still observe the issue.. Also make sure you are not leaking any bitmaps.. recycle the bitmap as and when possible to free native memory associated with the image

The Natïve heap is shared between running applications, so the amount of free space depends on what other applications are running and their bitmap usage. You can find out the native heap allocated and based on the available heap you can allocate resources:

Refer: long nativeHeapAllocated = Debug.getNativeHeapAllocatedSize();

refer this to learn more about native heap allocations:http://sourcevirtues.wordpress.com/2013/01/14/java-heap-space-and-native-heap-problems/

rupesh jain
  • 3,410
  • 1
  • 14
  • 22
0

while moving to next activity you heap memory exits there comes the out of memory error . My suggestion is, clear all your used bitmap to null or do recycle your bitmap as @Deimos said

bitmap.recycle();
bitmap=null;

see the link for more clarification link1 link2

The same out of memory occurs in my project where i'm using bitmap images to my imageview for all next level. So what i did means when ever i switched to next level i clear all the bitmap resource to null and it works for me.

Community
  • 1
  • 1
SaravanaRaja
  • 3,228
  • 2
  • 21
  • 29