2

How do I know how much memory is available for my app on the fly? My app downloads some bitmaps and saves (in memory) them so not to bug the user by downloading it again. But the Java's heap is only 16MB, as far as I know, so I will need to handle some low memory cases and throw away some downloaded bitmaps (not all the bitmaps are shown at the same time, but they might be visible to the user with a single "click", if they are already downloaded).

Is there a way to get the actual available memory (which means, the Java heap available memory)?

4
  • The first is reporting "disk-like" private storage area, the second system ram statistics. Commented Aug 24, 2011 at 14:04
  • Thanks for the info Chris Stratton. I removed the unnecessary links I left only the desired information then... Commented Aug 24, 2011 at 14:10
  • First you probably need to decide if you want download them t keep in non-volatile storage on the device, ie, private files area or shared external storage ("sdcard") so they persist across sessions. Then you can think about having them in memory, or loading them as needed, or various on-demand automatic schemes. Commented Aug 24, 2011 at 14:13
  • I would like to avoid keeping files on sdcard because of the extremely slow nature of it. I will try Zack's suggestion though, for it seems promising. Commented Aug 24, 2011 at 14:17

2 Answers 2

2

A blog on Android memory

http://codelog.dexetra.com/post/47690459692/getting-around-android-memory-blues

check it out ..it may help u..

Sign up to request clarification or add additional context in comments.

2 Comments

I'll mark your answer because of the Patrick Dubroy's presentation at Google I/O 2011 that is in the link that you posted. It's an excellent presentation, very informative and really helped me out. Thanks
The link is dead. Please add relevant information to your post.
2

Instead of worrying about all this, consider wrapping the object that represents each image in a WeakReference. Then just do caching with Map<String, WeakReference<Image>> or however you are doing it.

This way, if it's already in the cache, use it. If it's not in the cache (either it has never been accessed before or it's been GC'd) then get it again.

1 Comment

I will try it out. I'll wait to see if there is a way to get the available memory the way I explained though, so that other users might see the answer. (Just in case, vote up :D ...Good suggestion)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.