[android-developers] Re: How to release Drawable object from memory ?
I try this solution but it did not work anymore, even if I do System.gc() to call the garbage collector after setting to null the variable (calling this method does not guarantee that the garbage collector will actually be run). However, I manage to solve my problem resizing the image. First I get the image size using : BitmapFactory.decodeStream(InputStream is, Rect outPadding, BitmapFactory.Options opts) and setting opts.inJustDecodeBounds to true (to save memory). Image size is then got with opts.outHeight and opts.outWidth. Then, I calculate and set opts.inSampleSize value judging from the maximum image size I want. Finally, I call again BitmapFactory.decodeStream(InputStream is, Rect outPadding, BitmapFactory.Options opts) and get the resized image. On 28 nov, 03:59, Anirudh aithalanir...@gmail.com wrote: As a crude sort of way to get around this problem, you can assign your drawable references to null once you do not find a use for them so that the GC can free these allocations. On Nov 26, 10:23 am, daniel.benedykt daniel.bened...@gmail.com wrote: Hi Probably you are having a memory leak Read this article from google blog. http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks Hope this helps, Daniel On Nov 26, 3:42 pm, Syl sylvain.guyoma...@altran.com wrote: In my application, user can click on a button and then he can select a picture from his gallery. This image is then displayed. However, when the user performs 3 or 4 times this operation, the following exception is thrown, due to memory allocation problem : 11-26 18:31:34.119: ERROR/dalvikvm-heap(707): 6291456-byte external allocation too large for this process. 11-26 18:31:34.119: ERROR/(707): VM won't let us allocate 6291456 bytes 11-26 18:31:34.119: DEBUG/skia(707): allocPixelRef failed 11-26 18:31:36.005: DEBUG/AndroidRuntime(707): Shutting down VM 11-26 18:31:36.005: WARN/dalvikvm(707): threadid=3: thread exiting with uncaught exception (group=0x40013e28) 11-26 18:31:36.005: ERROR/AndroidRuntime(707): Uncaught handler: thread main exiting due to uncaught exception 11-26 18:31:36.099: ERROR/AndroidRuntime(707): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:304) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.graphics.drawable.Drawable.createFromStream(Drawable.java:635) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at com.altran.test.selectpicture.MainActivity.onActivityResult (MainActivity.java:74) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.Activity.dispatchActivityResult(Activity.java:3415) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread.deliverResults(ActivityThread.java:2835) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2881) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread.access$2300(ActivityThread.java:112) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1608) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.os.Handler.dispatchMessage(Handler.java:88) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.os.Looper.loop(Looper.java:123) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread.main(ActivityThread.java:3742) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at java.lang.reflect.Method.invokeNative(Native Method) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at java.lang.reflect.Method.invoke(Method.java:515) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:739) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at dalvik.system.NativeStart.main(Native Method) Here a sample of my code where problem is focused : InputStream is = getContentResolver().openInputStream( currImageURI ); Drawable drawable = Drawable.createFromStream( is, src ); is.close(); m_imageView.setBackgroundDrawable( drawable ); Is it possible to force object (here the Drawable object) to be released from memory ? Thanks. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to
[android-developers] Re: How to release Drawable object from memory ?
As a crude sort of way to get around this problem, you can assign your drawable references to null once you do not find a use for them so that the GC can free these allocations. On Nov 26, 10:23 am, daniel.benedykt daniel.bened...@gmail.com wrote: Hi Probably you are having a memory leak Read this article from google blog. http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks Hope this helps, Daniel On Nov 26, 3:42 pm, Syl sylvain.guyoma...@altran.com wrote: In my application, user can click on a button and then he can select a picture from his gallery. This image is then displayed. However, when the user performs 3 or 4 times this operation, the following exception is thrown, due to memory allocation problem : 11-26 18:31:34.119: ERROR/dalvikvm-heap(707): 6291456-byte external allocation too large for this process. 11-26 18:31:34.119: ERROR/(707): VM won't let us allocate 6291456 bytes 11-26 18:31:34.119: DEBUG/skia(707): allocPixelRef failed 11-26 18:31:36.005: DEBUG/AndroidRuntime(707): Shutting down VM 11-26 18:31:36.005: WARN/dalvikvm(707): threadid=3: thread exiting with uncaught exception (group=0x40013e28) 11-26 18:31:36.005: ERROR/AndroidRuntime(707): Uncaught handler: thread main exiting due to uncaught exception 11-26 18:31:36.099: ERROR/AndroidRuntime(707): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:304) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.graphics.drawable.Drawable.createFromStream(Drawable.java:635) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at com.altran.test.selectpicture.MainActivity.onActivityResult (MainActivity.java:74) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.Activity.dispatchActivityResult(Activity.java:3415) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread.deliverResults(ActivityThread.java:2835) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2881) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread.access$2300(ActivityThread.java:112) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1608) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.os.Handler.dispatchMessage(Handler.java:88) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.os.Looper.loop(Looper.java:123) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread.main(ActivityThread.java:3742) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at java.lang.reflect.Method.invokeNative(Native Method) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at java.lang.reflect.Method.invoke(Method.java:515) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:739) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at dalvik.system.NativeStart.main(Native Method) Here a sample of my code where problem is focused : InputStream is = getContentResolver().openInputStream( currImageURI ); Drawable drawable = Drawable.createFromStream( is, src ); is.close(); m_imageView.setBackgroundDrawable( drawable ); Is it possible to force object (here the Drawable object) to be released from memory ? Thanks. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to release Drawable object from memory ?
Hi Probably you are having a memory leak Read this article from google blog. http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html Hope this helps, Daniel On Nov 26, 3:42 pm, Syl sylvain.guyoma...@altran.com wrote: In my application, user can click on a button and then he can select a picture from his gallery. This image is then displayed. However, when the user performs 3 or 4 times this operation, the following exception is thrown, due to memory allocation problem : 11-26 18:31:34.119: ERROR/dalvikvm-heap(707): 6291456-byte external allocation too large for this process. 11-26 18:31:34.119: ERROR/(707): VM won't let us allocate 6291456 bytes 11-26 18:31:34.119: DEBUG/skia(707): allocPixelRef failed 11-26 18:31:36.005: DEBUG/AndroidRuntime(707): Shutting down VM 11-26 18:31:36.005: WARN/dalvikvm(707): threadid=3: thread exiting with uncaught exception (group=0x40013e28) 11-26 18:31:36.005: ERROR/AndroidRuntime(707): Uncaught handler: thread main exiting due to uncaught exception 11-26 18:31:36.099: ERROR/AndroidRuntime(707): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:304) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.graphics.drawable.Drawable.createFromStream(Drawable.java:635) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at com.altran.test.selectpicture.MainActivity.onActivityResult (MainActivity.java:74) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.Activity.dispatchActivityResult(Activity.java:3415) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread.deliverResults(ActivityThread.java:2835) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2881) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread.access$2300(ActivityThread.java:112) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1608) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.os.Handler.dispatchMessage(Handler.java:88) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.os.Looper.loop(Looper.java:123) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at android.app.ActivityThread.main(ActivityThread.java:3742) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at java.lang.reflect.Method.invokeNative(Native Method) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at java.lang.reflect.Method.invoke(Method.java:515) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:739) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) 11-26 18:31:36.099: ERROR/AndroidRuntime(707): at dalvik.system.NativeStart.main(Native Method) Here a sample of my code where problem is focused : InputStream is = getContentResolver().openInputStream( currImageURI ); Drawable drawable = Drawable.createFromStream( is, src ); is.close(); m_imageView.setBackgroundDrawable( drawable ); Is it possible to force object (here the Drawable object) to be released from memory ? Thanks. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en