How to check memory leak in Xamarin.Android?

2019-04-28 06:34发布

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?

2条回答
做个烂人
2楼-- · 2019-04-28 07:09

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

查看更多
Explosion°爆炸
3楼-- · 2019-04-28 07:15

You can try Xamarin Profiler https://www.xamarin.com/profiler In Memory snapshots, you will see if there is the memory leak. But from my experience, if you get out of memory exception, may cause by you use large size image in your Android project.

查看更多
登录 后发表回答