0

In my project,i am noticing out of memory error in my emulator like below

    08-03 01:38:28.995: W/dalvikvm(1040): threadid=1: thread exiting with uncaught exception (group=0x40015560)
    08-03 01:38:29.045: E/AndroidRuntime(1040): FATAL EXCEPTION: main
    08-03 01:38:29.045: E/AndroidRuntime(1040): java.lang.RuntimeException: Unable to  start activity ComponentInfo{sdei.edustatus/sdei.edustatus.gradebook.GradeBookActivity}:  android.view.InflateException: Binary XML file line #78: Error inflating class <unknown>
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.os.Handler.dispatchMessage(Handler.java:99)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.os.Looper.loop(Looper.java:123)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.ActivityThread.main(ActivityThread.java:3683)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at java.lang.reflect.Method.invokeNative(Native Method)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at java.lang.reflect.Method.invoke(Method.java:507)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at dalvik.system.NativeStart.main(Native Method)
    08-03 01:38:29.045: E/AndroidRuntime(1040): Caused by: android.view.InflateException: Binary XML file line #78: Error inflating class <unknown>
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.Activity.setContentView(Activity.java:1657)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at sdei.edustatus.gradebook.GradeBookActivity.onCreate(GradeBookActivity.java:311)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     ... 11 more
    08-03 01:38:29.045: E/AndroidRuntime(1040): Caused by: java.lang.reflect.InvocationTargetException
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at java.lang.reflect.Constructor.constructNative(Native Method)
    03 01:38:29.045: E/AndroidRuntime(1040):    at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     ... 22 more
    08-03 01:38:29.045: E/AndroidRuntime(1040): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.content.res.Resources.loadDrawable(Resources.java:1709)
   08-03 01:38:29.045: E/AndroidRuntime(1040):  at   android.content.res.TypedArray.getDrawable(TypedArray.java:601)
   08-03 01:38:29.045: E/AndroidRuntime(1040):  at android.view.View.<init>(View.java:1951)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.View.<init>(View.java:1899)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.ViewGroup.<init>(ViewGroup.java:286)
        08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.widget.RelativeLayout.<init>            (RelativeLayout.java:173)
     08-03 01:38:29.045: E/AndroidRuntime(1040):    ... 25 more

I don't think there should be any memory leaks.Yes i am using some images,do i need to handle them separately????????? My application's size is 2.4mb.

What should i do?

orange
  • 37
  • 1
  • 8
  • If you hold on to a reference of something it can still create memory leaks. Find something which is being created but never losing scope. – VoronoiPotato Aug 03 '12 at 15:09

3 Answers3

3

In java,i don't think there should be any memory leaks because of gc

is wrong statement. If code introduces memory leak, jvm can't do anything.

In your case, error is

Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

It seems you are trying to load bitmap image with big size (which dalvik doesn't support). There are lot of discussions on SO related to this issue, here and here.

Community
  • 1
  • 1
kosa
  • 65,990
  • 13
  • 130
  • 167
  • Speaking pedantically java doesn't have memory leaks, because you can always get the objects that you forgot to dispose. – Andrey Aug 03 '12 at 15:10
  • @Andrey pedantic or not, that's just a silly thing to say. You could just as well say that C++ doesn't have memory leaks either because you can always scan memory for the objects that you forgot to dispose. – David Wasser Aug 03 '12 at 15:48
  • @DavidWasser First of all it is not very polite to one's opinion silly if you disagree with it. Check the definition of memory leak here: http://en.wikipedia.org/wiki/Memory_leak , then check http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java , and find that a lot of people don't consider these as true memory leak. Scanning memory doesn't count as a real way to access objects. – Andrey Aug 03 '12 at 16:07
0

I take it you are using the eclipse emulator?

If that's the case it may not have sufficient memory/disk settings to display the image as highlighted by this line:

Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

Check your settings under eclipse (again if your using it) by going to AVD, select your virtual device and hit edit. You will see the SD card size and memory settings under hardware. I think there is a limit on the size of memory you can allocate the emulator so its better to use a phone.

Have you tried debugging on an actual device, its usually better!

EDIT:

In fact you might have this issue too:

java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android

Community
  • 1
  • 1
David Hirst
  • 1,890
  • 2
  • 22
  • 31
  • Yes,I haven't noticed this in any real device.I have given a sufficient amount of memory for my emulator about 500mb. – orange Aug 03 '12 at 15:16
0

There are a couple of things:

1) make sure you don't have memory leaks, for this profile your code, for example, use MAT (http://www.eclipse.org/mat/)

2) Do proper memory management for images; use SoftReferences and WeakReferences

3) There are a number of implementations that you can find on the web (google it) for Image cache and Image donwloaders (w/ cache) -- search and pick the one you like best.

But always do #1 above.

CEO
  • 270
  • 3
  • 6