###Android Memory
To find out how much memory you have available for your app - ActivityManager.getMemoryClass() Android G1 - 16MB Motorola Xoom - 48GB
If you need more, use android:largeHeap = "true"
Can't just ask for more memory though. Using the large heap option and getting more memory means more time spent in garbage collection.
- Garbage collection
The GC visits all objects in the graph. Objects that it does not visit are collected.
After Gingerbread, the GC changed from Stop the World, full heap collection (>100ms pauses) to Concurrent, partial collection (<5ms pauses).
- Tools to analyse Memory Usage
####Logs
A log of dlavik would give the following info
-
Reason for GC (GC_CONCURRENT, GC_FOR_MALLOC, GC_EXTERNAL_ALLOC(deprecated), GC_EXPLICIT (avoid))
-
The amount of memory freed
-
How much of the heap is free
-
External memory statistics
-
Pause time
A technique he suggests for detecting memory leak is to look at the size of the memory used. If it goes up steadily without going down, its possible that there is a leak.
####Heap Dump
- Create with DDMS
Memory leaks can occur in garbage collected languages, just like it does in C. If you hold reference to a long lived object like Activity (or even its children like ViewGroup or View), it will cause a leak. For example, when a rotation takes place, the activity is collected and a new one is created. If a reference to the old one still exists, then it won't be collected.
The "retained heap" of an object is the amount of memory that would be freed if we freed the object and objects that it holds references to. A dominator tree is used to decide whether an object is a child of another.