Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am performing animation in android application. When running the my application is crash and getting OutOfMemoryException. The error are, java.lang.OutOfMemoryError: Failed to allocate a 9437196 byte allocation with 3044192 free bytes and 2MB until OOM
My Logcat are given below,
8:05.256 9298-9298/ayurjanaapp.dell.xerces.com.ayurjnanaapp E/AndroidRuntime: FATAL EXCEPTION: main
          Process: ayurjanaapp.dell.xerces.com.ayurjnanaapp, PID: 9298
          java.lang.OutOfMemoryError: Failed to allocate a 9437196 byte allocation with 3044192 free bytes and 2MB until OOM
              at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
              at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
              at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
              at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
              at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
              at android.content.res.Resources.loadDrawableForCookie(Resources.java:2638)
              at android.content.res.Resources.loadDrawable(Resources.java:2543)
              at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
              at android.widget.ImageView.<init>(ImageView.java:162)
              at android.widget.ImageView.<init>(ImageView.java:150)
              at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
              at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
              at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
              at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1013)
              at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1072)
              at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
              at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
              at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
              at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
              at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
              at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
              at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
              at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
              at android.app.Dialog.setContentView(Dialog.java:512)
              at ayurjanaapp.dell.xerces.com.ayurjnanaapp.AnimationForSubsequentBellsActivity.showBellDialog(AnimationForSubsequentBellsActivity.java:41)
              at ayurjanaapp.dell.xerces.com.ayurjnanaapp.AnimationForSubsequentBellsActivity.onCreate(AnimationForSubsequentBellsActivity.java:31)
              at android.app.Activity.performCreate(Activity.java:6259)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
              at android.app.ActivityThread.access$900(ActivityThread.java:154)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:148)
              at android.app.ActivityThread.main(ActivityThread.java:5443)
              at java.lang.reflect.Method.invoke(Native Method)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  12-05 10:4
So, please help me for solving this above problem. Thank you.


What I have tried:

I tried to add largeHeap=true statement in my manifest file, but this is not the right solution. 
Posted
Updated 9-Dec-16 12:23pm
Comments
Richard MacCutchan 5-Dec-16 5:05am    
OutOfMemoryException usually occurs because you have used up all available physical memory. Increasing the heap size will not help. You need to find out why your app is using so much memory, and correct it.
Member 12299159 5-Dec-16 5:07am    
In the my application I am performing animation of images. When running the animation, it crash and giving OutOfMemoryException. How I solve?
Richard MacCutchan 10-Dec-16 4:12am    
You solve it by not trying to use memory that does not exist.

There are a number of ways to check out the solution of the problem:
java.lang.OutOfMemoryError Solution[^]
 
Share this answer
 
Quote:
Failed to allocate a 9437196 byte allocation with 3044192 free bytes
Your app is trying to allocate all physical memory and more.
You need to discover where and why your app need so much memory, you may have a memory leak, or you don't free memory when you don't need it any more.
The only useful advise is to use the debugger and put breakpoints on key parts of the app to detect where it eats memory. As you get knowledge, move the breakpoints to interesting parts to marrow the research. Then study the code to understand why the app need so much memory.
This is a tedious task and we can't do it for you. The first obvious reason is that we don't have the app.
-----
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900