Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do memory profiling for an android application? [duplicate]

I need to check my application for memory leaks, i also need to see the memory allocation of my application. I downloaded and installed eclipse memory analyzer, and it looks like the first step is to open a heap dump. But what is a heap dump, how can i create a heap dump. And how exactly am i going to use this software, I did some googling but i couldn't find any useful information thanks

like image 600
aryaxt Avatar asked Jun 24 '10 18:06

aryaxt


People also ask

Which profiling will analyze the memory usage of the application?

When the Diagnostic Tools window appears, choose the Memory Usage tab, and then choose Heap Profiling.

How do you find memory leaks inside apps?

If you suspect you are running into a temporal leak, a good way to check is to use Android Studio's memory profiler. Once you start a session within the profiler, take the steps to reproduce the leak, but wait for a longer period of time before dumping the heap and inspecting. The leak may be gone after the extra time.


2 Answers

When you debug your app, open DDMS in Eclipse. On the toolbar there is a heap dump button that you can use to generate a heap dump to view in Eclipse memory analyzer. This is only supported I think with the 1.6+ or 2.0+ SDK.

like image 163
Robby Pond Avatar answered Oct 11 '22 14:10

Robby Pond


The heap dump of the dalvik VM needs to be converted to regular hprof format using the hprof-conv.exe converter tool in the tools directory of the Android SDK. You can open this hprof with Eclipse MAT or other tools are: YourKit http://www.yourkit.com/ and JProbe http://www.quest.com/jprobe/

Beside DDMS you can also create the hprof from you app/code (only newer SDKs) via Debug.dumpHprofData(...)

Note that in DDMS you can see the heap that your app is using. It doesn't show the native heap that external resources such as bitmaps are allocating. Nevertheless, these resources also need to be taken into account when checking for memory leaks. When both native and app heap adds up to 16MB / resp. 24MB you will get an OOM error.

You can see the native heap that's been used (i.e. by bitmaps in your app) via Debug.getNativHeapAllocatedSize().

like image 29
Mathias Conradt Avatar answered Oct 11 '22 13:10

Mathias Conradt