I am drawing bitmaps left and right and I hit this issue where I create a bitmap in one section of my code and when I later try to draw on it using canvas, i get bitmap recycled. but I did not null if out, or call its recycle method.
Description: I have a main Class that extends View that when first loads, initiates the main screen which loads/draws on bitmaps and no problem. I then added a key event that causes this screen to go away and load the next screen. The screen logic is encapsulated in a class that I already instantiated in the Main Class constructor and in my second screen its constructor is this code: staticBg = new BitmapDrawable(Bitmap.createBitmap(320, 240, Bitmap.Config.RGB_565)); staticGr = new Canvas( staticBg.getBitmap() ); at a later time, from my first screen when I push a button, i call my init() function that trys load screen two which does a draw to this bitmap and I get the following error: 03-06 08:52:56.301: ERROR/AndroidRuntime(846): java.lang.NullPointerException 03-06 08:52:56.301: ERROR/AndroidRuntime(846): at android.graphics.Canvas.throwIfRecycled(Canvas.java:890) 03-06 08:52:56.301: ERROR/AndroidRuntime(846): at android.graphics.Canvas.drawBitmap(Canvas.java:911) It is saying my bitmap is recycled BUT from what I understand that does not happened unless you explicitly call it or the garbage collector does when there are no more references to it BUT i obviously still have a reference to it. What am I doing wrong? On Mar 1, 12:57 am, "bra...@gmail.com" <peacoc...@gmail.com> wrote: > Best darn suggestion yet. Thankyou I was wondering if I could use that > setting, but feared that perhaps I would not be able to generate new > bitmaps from the original - you can - thankyou > > On Feb 27, 1:19 pm, Alexey Krasnoriadtsev <ale...@agilefusion.com> > wrote: > > > There best working approach is to only load Bounds of the image, and > > then use scale to load the Bitmap of the needed size. > > This way you never load the full-size bitmap in the memory. > > >http://code.google.com/intl/ja/android/reference/android/graphics/Bit... > > > get the bounds, and then use those to calculate the appropriate sample > > size. > > > On Feb 26, 2:36 pm, mark.ka...@gmail.com wrote: > > > > I'm just saying there have been a number of threads on this issue, > > > I've had out of memory problems when processing bitmaps, and so have > > > many other developers. It looks to me like a bug IMHO. I hope this > > > problem will be resolved at some point. > > > > On Feb 26, 2:02 pm, "bra...@gmail.com" <peacoc...@gmail.com> wrote: > > > > > If that is the case then why does calling myBitmap.recycle not give me > > > > that memory back to use for the next time I go into an edit. > > > > > On Feb 26, 4:59 pm, Romain Guy <romain...@google.com> wrote: > > > > > > BitmapFactory does NOT leak Bitmaps. > > > > > > A 2056x1536 opaque image requires 6 MB of RAM. An application has 16 > > > > > MB max. Do the math. > > > > > > On Thu, Feb 26, 2009 at 1:50 PM, <mark.ka...@gmail.com> wrote: > > > > > > > Are you using BitmapFactory? There have been a number of threads > > > > > > about memory leaks, or similar problems when using BitmapFactory to > > > > > > process bitmaps. Using Bitmap.recycle may mitigate, but not > > > > > > eliminate > > > > > > these types of problems. > > > > > > > M > > > > > > > On Feb 26, 11:39 am, Mattaku Betsujin <mattaku.betsu...@gmail.com> > > > > > > wrote: > > > > > >> I think the best solution to handle very large bitmaps is to be > > > > > >> able to > > > > > >> decode only a small chunk of the bitmap at a time and process it. > > > > > > >> Does anyone know if the existing Android API can support this? > > > > > > >> If not, probably one solution is to write a smart decoder (in > > > > > >> Java, so slow > > > > > >> :-( ....) that can decode a small chunk. > > > > > > >> On Thu, Feb 26, 2009 at 11:32 AM, Tomei Ningen > > > > > >> <tomei.nin...@yahoo.com>wrote: > > > > > > >> > You're running into memory fragmentation problems. Bitmap memory > > > > > >> > is > > > > > >> > not allocated from the Java object heap. Instead, it's allocated > > > > > >> > from > > > > > >> > the 'malloc' heap. That's why you don't see the Java heap > > > > > >> > expanding. > > > > > > >> > How big is your bitmap? If you're processing JPEG files, > > > > > >> > probably it > > > > > >> > will be better to read the thumbnail directly from the JPEG > > > > > >> > file. This > > > > > >> > way you don't need to create the Bitmap at all. > > > > > > >> > On Feb 26, 9:47 am, "bra...@gmail.com" <peacoc...@gmail.com> > > > > > >> > wrote: > > > > > >> > > Ok I am at the end of my rope. > > > > > > >> > > I am doing some image processing. I have a large image file > > > > > >> > > which I > > > > > >> > > open and create a smaller bitmap from. At the end of > > > > > >> > > processing I call > > > > > >> > > recycle on everything. I null everything. I run GC manually. > > > > > > >> > > I then try edit another image and I get an out of VM memory > > > > > >> > > error. > > > > > >> > > Bitmap exceeds etc etc. > > > > > > >> > > I am looking at the heap and the secone edit doesnt seem to > > > > > >> > > cause it > > > > > >> > > to increase at all. > > > > > > >> > > What else can I do. Surely google cannot possibly be > > > > > >> > > suggesting that > > > > > >> > > we can open one large bitmap per session and thats it?- Hide > > > > > >> > > quoted text - > > > > > > >> - Show quoted text - > > > > > > -- > > > > > Romain Guy > > > > > Android framework engineer > > > > > romain...@android.com > > > > > > 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- Hide > > > > > quoted text - > > > > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---