1) 3-4M for one image is a lot since you have total of 16M for the whole app! Dunno the answer to your question 2) 25*256K in bitmaps is already over 6,4M. Added to 1) makes already over 10M! AFAIK you should only use .recycle() if you really don't need them anymore. Unclear to me what "really don't need" means. 3) 32x32 pixels is about 204800 bytes if you count 4 bytes per pixel 4) These icons are probably not big right?
The allocation tracker didn't give enough details for me, so am using the Eclipse Memory Analyzer Tool. Here's a pretty handy tutorial on how to use it & detect memory leaks, maybe useful: http://ttlnews.blogspot.com/2010/01/attacking-memory-problems-on-android.html On 16 jun, 01:24, Nathan <[email protected]> wrote: > I'm running into OutOfMemoryErrors when allocating bitmaps. This is > not something I can reproduce with emulators, and has been reported by > a few beta testers with the HTC Incredible. > > I'm not sure I can solve this directly, and my best hope is to follow > best practices for bitmaps and memory thereof. But looking for those > best practices based on groups archives left me with more questions > than answers. If anyone has a chapter about this in their book, I will > buy the book. > > Here are the things I've mulled over so far: > > 1. I have a bitmap for a drawing buffer. It is about 3-4 megabytes on > some devices. This is the biggest bitmap I have, and without it, I > wouldn't be able to much of anything useful in my app. I am assuming > that it would not be useful to use inPurgeable if this is a bitmap > that is drawn into. Is this true? > > 2. Next biggest in the hierarchy are some bitmaps that are about 22K > bytes and 256K unpacked. Since I believe about 25 of these might be > used at one time, I have a cache with a size of 25. > I am careful to use BitmapFactory.Options.InPurgeable, so I believe > that could make them take only 22K each, but I don't see that as > guaranteed. Maybe they are taking 256K each, which would put me in the > danger zone. > As they are cycled out of the cache, I call bitmap.recycle(). I think > this a good practice. Is it? > > 3. Next are some resources with icon size 32x32 pixels. There are > about 50 that could be used or reused. If I use code like this: > > Drawable s = > mCtx.getResources().getDrawable(R.drawable.symbol_icon); > Where s is a local variable to rendering. Suppose I call this 37 > times. > Am I to assume that Android will do something smart like create only > one bitmap for this resource even if it is used 37 times? > Or am I to assume that Android will do something stupid like create 37 > bitmaps and keep references in an obscure location that will prevent > garbage collection? > Do I need to get more access to these bitmaps and do something smart > myself? > > 4. Finally are some other icons used for menus and ImageButtons. Most > are declared in layout files - so I don't touch the bitmaps directly. > > Can someone better informed than me comment on these assumptions? I'd > like to make my memory usage more efficient, but don't want to spend > time on things that will amount to shuffling chairs on the Titanic. > > And how do I best measure this usage? Interestingly enough, I've tried > using the Allocation Tracker and it says I haven't allocated a single > bitmap. In light of the above, I don't think that's right. > > Thanks in advance. > > Nathan -- 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

