Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining available memory on Android

So one of the challenges on Android is various device specifications (in particular device memory).

I've written my model objects to extensively use Java SoftReferences in a lazy load fashion, so the VM is free to trim not currently used parts of the data model as it sees fit and they are just reconstituted as needed.

However, one challenge in practice with SoftReferences is that they tend to be cleared within a few seconds of become weakly referenced as opposed to hanging around until the VM is low on memory, so they work well in terms of allowing the model to trim, but they don't work as well in that it often means nothing is in memory. Ideally on a device with plenty of memory, you'd let the user benefit from keeping objects in memory.

As a result, it's common to combine SoftReferences with an LRU mechanism, where the LRU keeps a hard pointer to the recently referenced objects. This of course is not ideal since it assumes that you have enough memory for all these hardly referenced objects.

It also makes it a challenge to know what is a good default for the LRU.

In a perfect world, Android would use it's low memory callback as a hint (so I could possibly start with a small LRU, and periodically bump it up until low memory callbacks started occurring then back it off to find a good value for a device), but in my experience this callback never seems to coincide with actual VM memory pressure.

Has anyone come across a reasonable way of detecting that your data model is using too much memory on a particular device?

like image 752
Bryant Harris Avatar asked Sep 18 '12 13:09

Bryant Harris


1 Answers

if you want to determine available memory in android , then you can check or go to in perspective - >ddms 2) second thing is you can use memory analyzer tools checked in used and unused memory, you also check availability of memory.

like image 81
Satyam Avatar answered Sep 21 '22 07:09

Satyam