Any way to avoid garbage collection on these lines? Bitmap.createBitmap / new Canvas(bitmap)

by admin.androidsl...@googlemail.com » Tue, 14 Apr 2009 21:23:13 GMT


Sponsored Links
 Running these many times in my app loop :

Bitmap bitmap = Bitmap.createBitmap(320, 480, Config.RGB_565);
Canvas canvas = new Canvas(bitmap);

I'm thinking of caching either / both of these objects, but don't want
to get out of memory errors either!



--~--~---------~--~----~------------~-------~--~----~



Any way to avoid garbage collection on these lines? Bitmap.createBitmap / new Canvas(bitmap)

by Streets Of Boston » Tue, 14 Apr 2009 21:51:56 GMT


 If this bitmap is used for displaying only one item (image), why do
you create a new bitmap over and over again?

once:
mBitmap = Bitmap.createBitmap(320,480,Config.RGB_565);
...
...
many times:
Canvas canvas = new Canvas(mBitmap);
// clear canvas
// draw into canvas
...
..

On Apr 14, 9:22am, "admin.androidsl...@googlemail.com"


--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Any way to avoid garbage collection on these lines? Bitmap.createBitmap / new Canvas(bitmap)

by admin.androidsl...@googlemail.com » Tue, 14 Apr 2009 22:05:48 GMT


 I'm happy to keep a static or member reference to the Bitmap object
for future usage - but I'm worried if that will reduce the amount of
memory available to my app?

Alex





--~--~---------~--~----~------------~-------~--~----~



Any way to avoid garbage collection on these lines? Bitmap.createBitmap / new Canvas(bitmap)

by Streets Of Boston » Tue, 14 Apr 2009 22:57:07 GMT


 In one of my apps i have similar concerns. I cache a bunch of bitmaps
to improve the user experience (using Map). However, at some point in
my app, the app needs the memory (preparing for image-editing on full-
sized image).

This is what i did:
I wrote a class to which bitmap-caches can register them selves.
This class provides a static method called 'tryToReclaimBitmapMemory
()' which will loop over all the registered bitmap-caches and asks
them to clear their caches and, if possible, recycle their bitmaps.
After this it'll call 'System.gc()' for good measure :)

Whenever my app reaches a point where it needs as much (bitmap) memory
as possible, it will call this static method 'tryToReclaimBitmapMemory
()'.

In this way, i can keep cached bitmaps and i'm only zapping them when
really necessary.

On Apr 14, 10:05am, "admin.androidsl...@googlemail.com"




--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Cloud based apps

I recently saw the VP of Mobile initiatives in Google (Vic Gundotra)
touting the importance of  browser based apps on Android and other
platforms. Given the popularity if Webkit , boradband penetration in
mobile, shouldn't this be the way to go as opposed to the traditional
'client-server' type apps most of us are developing on Android?

Where do you think this development is headed?

Sri
--~--~---------~--~----~------------~-------~--~----~

2. Will SyncML engine be available in Android?

Hi Experts,
Is there a plan to add SyncML engine to Android platform? I just heard
from someone that Esmertec AG is going to implement a SyncML engine
and will be contributing it back to Android, is it true?

Regards,
DH
--~--~---------~--~----~------------~-------~--~----~

3. How the R.java file is updated when I modify a default app in the Android source code?

4. help please!

5. Problem with setTheme() method

6. Dynamically loading a .jar file at Runtime

7. How to specify the length of the EditText in a Table row