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. Radio button layout.

My RadioGroup isn't working properly. By now, I've figured out that
RadioButtons have to be direct descendants of RadioGroup. At least, it
seems to be that way for the last two years.

In that case, what I would like line up two EditViews and a Spinner on
the right with the three RadioButtons on the left column, to enter
additional information about each choice.

It seems like a RelativeLayout would help, but it doesn't. Using
android:layout_toRightOf puts all three views on the upper left corner
of the Radio group.

Using a table layout makes it look right, but all the Radio buttons
can be activated simultaneously because they aren't direct children of
RadioGroup.

Has anyone solved this problem satisfactorily?

Note to Android contributors: I think there is a need to make the
RadioGroup views play nicer with other views and layouts.

Nathan

-- 

2. farid Rahman wants to chat

-----------------------------------------------------------------------

farid Rahman wants to stay in better touch using some of Google's coolest new
products.

If you already have Gmail or Google Talk, visit:
http://mail.google.com/mail/b-2051619234-c8d6b4fdcf-rael7sQFuxpf1bJHxxrrjHsQ0wI
You'll need to click this link to be able to chat with farid Rahman.

To get Gmail - a free email account from Google with over 2,800 megabytes of
storage - and chat with farid Rahman, visit:
http://mail.google.com/mail/a-2051619234-c8d6b4fdcf-rael7sQFuxpf1bJHxxrrjHsQ0wI

Gmail offers:
- Instant messaging right inside Gmail
- Powerful spam protection
- Built-in search for finding your messages and a helpful way of organizing
  emails into "conversations"
- No pop-up ads or untargeted banners - just text ads and related information
  that are relevant to the content of your messages

All this, and its yours for free. But wait, there's more! By opening a Gmail
account, you also get access to Google Talk, Google's instant messaging
service:

http://www.google.com/talk/

Google Talk offers:
- Web-based chat that you can use anywhere, without a download
- A contact list that's synchronized with your Gmail account
- Free, high quality PC-to-PC voice calls when you download the Google Talk
  client

We're working hard to add new features and make improvements, so we might also
ask for your comments and suggestions periodically. We appreciate your help in
making our products even better!

Thanks,
The Google Team

To learn more about Gmail and Google Talk, visit:
http://mail.google.com/mail/help/about.html
http://www.google.com/talk/about.html

(If clicking the URLs in this message does not work, copy and paste them into
the address bar of your browser).

-- 
"Indonesian Android Community [id-android]" 

3. Forward Locking and ZappMarket

4. AudioRecord: onPeriodicNotification and onMarkerReached are not called

5. AudioRecord creates a stereo file instead of a mono file.

6. Urgent Help: AudioTrack class ...Streaming Mode

7. Display progress of xml parsing?