Embed presentation
Download as PDF, PPTX

























![View.setTag(key,tag) - pre 4.0public static class MainActivity extends Activity { private final WeakHashMap<Parent, Parent.Child> mMap = new WeakHashMap<Parent, Parent.Child>(); @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); // If parents were collected OOM error wouldn't be thrown. But they aren't collected so we get OOM here. for (int i = 0; i < 1000; ++i) { final Parent parent = new Parent(); mMap.put( parent, parent.mChild ); } }}public static class Parent { public final Child mChild = new Child(); public class Child { private final byte[] mJunk = new byte[10*1024*1024]; }}](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmemoryanalyzertoolandmemoryoptimizationtipsin-121230065843-phpapp02%2f75%2fMemory-Analyzer-Tool-and-memory-optimization-tips-in-Android-26-2048.jpg&f=jpg&w=240)



The document discusses memory analysis and optimization tips for Android applications. It introduces the Eclipse Memory Analyzer tool, which can be used to analyze memory usage and find memory leaks. Some key points covered include the low RAM sizes on Android devices, how the garbage collector works, how to analyze an object's shallow size and retained size, finding memory dominators, and common memory leak pitfalls like non-static handlers and large bitmaps stored in static fields. The document encourages analyzing heap dumps in the Memory Analyzer tool to optimize memory usage and find leaks.

























![View.setTag(key,tag) - pre 4.0public static class MainActivity extends Activity { private final WeakHashMap<Parent, Parent.Child> mMap = new WeakHashMap<Parent, Parent.Child>(); @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); // If parents were collected OOM error wouldn't be thrown. But they aren't collected so we get OOM here. for (int i = 0; i < 1000; ++i) { final Parent parent = new Parent(); mMap.put( parent, parent.mChild ); } }}public static class Parent { public final Child mChild = new Child(); public class Child { private final byte[] mJunk = new byte[10*1024*1024]; }}](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmemoryanalyzertoolandmemoryoptimizationtipsin-121230065843-phpapp02%2f75%2fMemory-Analyzer-Tool-and-memory-optimization-tips-in-Android-26-2048.jpg&f=jpg&w=240)

