It looks like your application is leaking memory somehow. You can check out the various articles on the subject available at android-developers.blogspot.com.
On Tue, Apr 6, 2010 at 9:55 PM, patbenatar <[email protected]> wrote: > Romain- Thanks so much for your response! That helps me understand the > memory usage amount... What I don't get is why would Android not be > able to free up 4MB of RAM for me? Isn't memory Android's job? My > drawable is only referenced once, in my XML, and that XML is only > being loaded in one Activity's onCreate. That Activity may run > multiple times in one run of the app, but it always finishes and > should therefore be destroyed by the system, removing all pointers to > the View and the Drawable in it, and on the next GC run it should be > freed.. At least that's the theory.... Am I missing something? > > Android is surely capable of handling a 4MB drawable in RAM, is it > not? Maybe there is a way I can compress this image? I hope to > maintain full-resolution on the hi-dpi devices and it needs to fill > the screen in both landscape and portrait. I could shrink it down to > 854x854 as the minimum dimension to make it fit perfectly on the > Droid's pixel-packed screen... > > Thanks guys! > Nick > > > > > > On Apr 6, 6:19 pm, Romain Guy <[email protected]> wrote: >> A 1000x1000 32 bits image takes 4 MB in RAM :) >> >> >> >> On Tue, Apr 6, 2010 at 6:10 PM, patbenatar <[email protected]> wrote: >> > Thanks for your support, Yahel. The 135KB image is 1000x1000 pixels >> > [quite a large canvas], but this is to ensure it looks great on hi-dpi >> > screens at both portrait and landscape and at any sort of aspect >> > ratio.. I'm also using android:scaleType="centerCrop" in my XML >> > markup ... It's a PNG, as well. I saved it from Photoshop using "Save >> > As..." not "Save For Web & Devices..." [should I be using the >> > latter? .. either way its just a PNG file, I think "Save For Web & >> > Devices" just compresses it more]... >> >> > -Nick >> >> > On Apr 6, 2:20 am, Yahel <[email protected]> wrote: >> >> What are the type and size in pixels of your drawable ? >> >> >> As I understand it, Android uncompress jpegs to raw bytes when >> >> decoding images. >> >> >> Say if your Image is a big(huge ?) and highly compressed JPEG, then >> >> possibly you could run into an OOM. >> >> >> Just an hypothesis, Although exactly 4500000-byte sounds weird :s >> >> >> If this is the case, you can either reduce your drawable size or load >> >> it programmatically instead of via XML and then use >> >> BitmapFactory.Options.inSampleSize or inTempStorage >> >> :http://developer.android.com/intl/de/reference/android/graphics/Bitma... >> >> >> Yahel >> >> >> On 6 avr, 07:47, patbenatar <[email protected]> wrote: >> >> >> > Hey Androiders! >> >> >> > I'm running into a strange intermittent issue with my app.. Basically >> >> > every time the app resumes I check if its internal data [fetched from >> >> > a Web API] is outdated and if it is I push off to my Splash/Loader >> >> > activity while I fetch new data. This works great ALMOST all the >> >> > time... Then every once in a while the system gives me a >> >> > java.lang.RuntimeException < android.view.InflateException < >> >> > java.lang.reflect.InvocationTargetException < >> >> > java.lang.OutOfMemoryError [that's the simplified stack trace].. >> >> >> > Here is the whole stack trace: >> >> >> > E/dalvikvm-heap(12914): Heap Massage needed (4500000-byte external >> >> > allocation too big) >> >> > E/dalvikvm-heap(12914): Full GC (don't collect SoftReferences) >> >> > I/ActivityManager( 1078): Process com.amazon.mp3 (pid 12917) has died. >> >> > D/dalvikvm(12914): GC freed 188 objects / 10224 bytes in 54ms >> >> > E/dalvikvm-heap(12914): Full GC (collect SoftReferences) >> >> > D/dalvikvm(12914): GC freed 47 objects / 1968 bytes in 56ms >> >> > E/dalvikvm-heap(12914): Try and trim Heap Source >> >> > E/dalvikvm-heap(12914): Heap Massage was unsuccessful for 4500000- >> >> > bytes! >> >> > E/dalvikvm-heap(12914): Heap Massage has failed... >> >> > E/ (12914): VM won't let us allocate 4500000 bytes >> >> > D/AndroidRuntime(12914): Shutting down VM >> >> > W/dalvikvm(12914): threadid=3: thread exiting with uncaught exception >> >> > (group=0x4001b178) >> >> > E/AndroidRuntime(12914): Uncaught handler: thread main exiting due to >> >> > uncaught exception >> >> > E/AndroidRuntime(12914): java.lang.RuntimeException: Unable to start >> >> > activity ComponentInfo{com.apwit.grubtruck/ >> >> > com.apwit.grubtruck.Splash}: android.view.InflateException: Binary XML >> >> > file line #8: Error inflating class <unknown> >> >> > E/AndroidRuntime(12914): at >> >> > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: >> >> > 2496) >> >> > E/AndroidRuntime(12914): at >> >> > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: >> >> > 2512) >> >> > E/AndroidRuntime(12914): at android.app.ActivityThread.access >> >> > $2200(ActivityThread.java:119) >> >> > E/AndroidRuntime(12914): at android.app.ActivityThread >> >> > $H.handleMessage(ActivityThread.java:1863) >> >> > E/AndroidRuntime(12914): at >> >> > android.os.Handler.dispatchMessage(Handler.java:99) >> >> > E/AndroidRuntime(12914): at >> >> > android.os.Looper.loop(Looper.java:123) >> >> > E/AndroidRuntime(12914): at >> >> > android.app.ActivityThread.main(ActivityThread.java:4363) >> >> > E/AndroidRuntime(12914): at >> >> > java.lang.reflect.Method.invokeNative(Native Method) >> >> > E/AndroidRuntime(12914): at >> >> > java.lang.reflect.Method.invoke(Method.java:521) >> >> > E/AndroidRuntime(12914): at com.android.internal.os.ZygoteInit >> >> > $MethodAndArgsCaller.run(ZygoteInit.java:860) >> >> > E/AndroidRuntime(12914): at >> >> > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) >> >> > E/AndroidRuntime(12914): at dalvik.system.NativeStart.main(Native >> >> > Method) >> >> > E/AndroidRuntime(12914): Caused by: android.view.InflateException: >> >> > Binary XML file line #8: Error inflating class <unknown> >> >> > E/AndroidRuntime(12914): at >> >> > android.view.LayoutInflater.createView(LayoutInflater.java:513) >> >> > E/AndroidRuntime(12914): at >> >> > com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayo >> >> > utInflater.java: >> >> > 56) >> >> > E/AndroidRuntime(12914): at >> >> > android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) >> >> > E/AndroidRuntime(12914): at >> >> > android.view.LayoutInflater.rInflate(LayoutInflater.java:618) >> >> > E/AndroidRuntime(12914): at >> >> > android.view.LayoutInflater.inflate(LayoutInflater.java:407) >> >> > E/AndroidRuntime(12914): at >> >> > android.view.LayoutInflater.inflate(LayoutInflater.java:320) >> >> > E/AndroidRuntime(12914): at >> >> > android.view.LayoutInflater.inflate(LayoutInflater.java:276) >> >> > E/AndroidRuntime(12914): at >> >> > com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.jav >> >> > a: >> >> > 198) >> >> > E/AndroidRuntime(12914): at >> >> > android.app.Activity.setContentView(Activity.java:1622) >> >> > E/AndroidRuntime(12914): at >> >> > com.apwit.grubtruck.Splash.onCreate(Splash.java:45) >> >> > E/AndroidRuntime(12914): at >> >> > android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: >> >> > 1047) >> >> > E/AndroidRuntime(12914): at >> >> > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: >> >> > 2459) >> >> > E/AndroidRuntime(12914): ... 11 more >> >> > E/AndroidRuntime(12914): Caused by: >> >> > java.lang.reflect.InvocationTargetException >> >> > E/AndroidRuntime(12914): at >> >> > android.widget.ImageView.<init>(ImageView.java:105) >> >> > E/AndroidRuntime(12914): at >> >> > java.lang.reflect.Constructor.constructNative(Native Method) >> >> > E/AndroidRuntime(12914): at >> >> > java.lang.reflect.Constructor.newInstance(Constructor.java:446) >> >> > E/AndroidRuntime(12914): at >> >> > android.view.LayoutInflater.createView(LayoutInflater.java:500) >> >> > E/AndroidRuntime(12914): ... 22 more >> >> > E/AndroidRuntime(12914): Caused by: java.lang.OutOfMemoryError: bitmap >> >> > size exceeds VM budget >> >> > E/AndroidRuntime(12914): at >> >> > android.graphics.Bitmap.nativeCreate(Native Method) >> >> > E/AndroidRuntime(12914): at >> >> > android.graphics.Bitmap.createBitmap(Bitmap.java:468) >> >> > E/AndroidRuntime(12914): at >> >> > android.graphics.Bitmap.createBitmap(Bitmap.java:435) >> >> > E/AndroidRuntime(12914): at >> >> > android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340) >> >> > E/AndroidRuntime(12914): at >> >> > android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488) >> >> > E/AndroidRuntime(12914): at >> >> > android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462) >> >> > E/AndroidRuntime(12914): at >> >> > android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java: >> >> > 323) >> >> > E/AndroidRuntime(12914): at >> >> > android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java: >> >> > 697) >> >> > E/AndroidRuntime(12914): at >> >> > android.content.res.Resources.loadDrawable(Resources.java:1705) >> >> > E/AndroidRuntime(12914): at >> >> > android.content.res.TypedArray.getDrawable(TypedArray.java:548) >> >> > E/AndroidRuntime(12914): at >> >> > android.widget.ImageView.<init>(ImageView.java:115) >> >> > E/AndroidRuntime(12914): ... 26 more >> >> >> > So up there towards the top I see: E/ (12914): VM won't let us >> >> > allocate 4500000 bytes >> >> >> > But why on earth does the system need to allocate 4.5MB just to >> >> > display a real simple XML view that loads up two small enough drawable >> >> > resources [one is 66KB and the other 135KB].. I'm also using an >> >> > animation+interpolator to rotate the 66KB loading spinner image. >> >> >> > The only error in that stack trace that comes from my package is line >> >> > 2 of my Splash/Loader's onCreate: >> >> > setContentView(R.layout.splash); >> >> >> > So then I go and analyze my XML layout file splash.xml, and in the >> >> > stack it also tells us: android.view.InflateException: Binary XML file >> >> > line #8: Error inflating class <unknown> -- so I look at line 8 of >> >> > splash.xml and that is the first line of my <ImageView/> element that >> >> > loads up the 135KB.. Here is my XML file: >> >> >> > <?xml version="1.0" encoding="UTF-8"?> >> >> >> > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/ >> >> > android" >> >> > android:orientation="vertical" >> >> > android:layout_width="fill_parent" >> >> > android:layout_height="fill_parent"> >> >> >> > <ImageView android:id="@+id/splash_graphic" >> >> > android:layout_width="fill_parent" >> >> > android:layout_height="fill_parent" >> >> > android:scaleType="centerCrop" >> >> > android:src="@drawable/grub_truck_splash" /> >> >> >> > <LinearLayout >> >> > android:id="@+id/splash_loader_container" >> >> > android:layout_width="wrap_content" >> >> > android:layout_height="wrap_content" >> >> > android:layout_alignParentBottom="true" >> >> > >> >> ... >> >> read more » > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > > To unsubscribe, reply using "remove me" as the subject. > -- Romain Guy Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

