Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check memory leak in Xamarin.Android?

Could anyone share suggestions or ways to check memory in the Xamarin.Android platform using Xamarin Studio?

I have tried with the below option available in Xamarin Studio,

Tools > Instruments > Allocations

But in that, I can select only iOS devices in the options as in below image,

enter image description here

Is there any solution for this?

like image 925
Swathi Gopal Avatar asked Jul 12 '17 06:07

Swathi Gopal


People also ask

How to check memory leaks in Xamarin forms?

Profilers: Profiler is a great tool to analyze the application behavior and check for memory leaks. They can also be combined with native instruments to check memory allocations of native objects. I hope you already know how to use them as we have discussed xamarin profilers in PART- A.

What is the use of xamarin profiler?

You can use the Android Profiler to measure the performance of a Xamarin Android app built with Visual Studio – without the need for a Visual Studio Enterprise license.


1 Answers

Sadly, but you can't do it from Xamarin Studio in any reliable way. You can try profiler, but it requires Enterprise license. My suggestion is to use standard Android tools.

PREPARATION:

1) Download "Eclipse Memory Analyzer"

2) Find Android Device Monitor. Bundled with Android SDK and can be found at "Android-SKD/tools/monitor". You can find out location of that folder by opening Xamarin, pressing CMD + , and selecting SDK Locations.

enter image description here enter image description here

3) Find Heap Snapshot converter (from Android to Java). Bundled with Android SDK and can be found at "Android-SDK/platform-tools/hprof-conv"

enter image description here

CAPTURE:

1) Install application with debug mode on device

2) Connect device to PC and launch monitor (2 step at preparation)

3) Launch the application and find it by application ID in devices.

enter image description here

4) Press Update Heap (icon to the right from bug icon)

5) Do stuff that you think makes leaks

6) Press Save Heap (icon to the right of start) and save it to the drive

RETRIEVER RESULTS:

1) Convert android Heap to Java Heap

1.1) Launch terminal

1.2) Locate Heap Shanpshot converter (hprof-conv) (3 step at preparation)

1.3) drop hprof-conv to terminal

1.4) drop Android heap, and then, drop it next and rename it. It will create correct copy in the same location with chosen name

android-sdk-macosx/platform-tools/hprof-conv raw.hprof converted.hprof

enter image description here

2) Open Eclipse Memory Analyzer (1 step at preparation)

3) Import acquired Head Dump

enter image description here

3) Select Leak Suspects Report

enter image description here

4) View results

enter image description here

like image 156
Taier Avatar answered Sep 19 '22 11:09

Taier