Question

I had window leak in my application activity which i fixed. But, when i tested the app using Memory Analyzer Tool in android - Histogram View, i find 2 instances of my activity.

Class Name | Objects | Shallow Heap | Retained Heap

.MATDemoActivity. | | |
com.pace.mat.MATDemoActivity | 2 | 368 |

Total: 1 entry (2,195 filtered)| | |

Since there is no memory leak, how can it be 2 objects ? Kindly help me understand the data in MAT result .... Thanks in advance

Please find the complete code and the related discussion in this link.

Android Memoryleak in code

=================

I found that when i start from Activity 1st -> 2nd -> 1st. Shallow Heap of 1st activity class = 2 and 2nd activity class = 1 and when i move from 1st -> 2nd -> 1st -> 2nd ... Shallow Heap of 1st activity class = 1 and 2nd activity class = 2.

So i tried with launch modes. i set android:launchMode="singleTask" for all activities. Now shallow heap for both the activities are equal to number of times i navigate to the page. But since multiple instances are not allowed in this launch mode, why am i not getting the shallow heap object count as 1 ?

Please share your ideas which would help me understand this better.

Was it helpful?

Solution 2

In android, we can use Memory Analyser tool to capture the memory leaks(if any) in a particular code. We should generate the heap dump just before performing the operation responsible for leak and after completing the operation. Compare these 2 dumps and find which objects are taking memory and why it is not garbage collected.

In my case mentioned above, i rather than analysing the dump generated after going to 2nd activity, i tried to compare the dumps before and after the activity. I got the required results clearly.

Also, regarding MAT tool, it is good to try more than once and compare the dumps and choose a dump for analysis.

Thanks friends.

OTHER TIPS

Creating unwanted objects in activity will lead to the memory leaks.So its so important that you should avoid creating the objects of classes which is of no use.These will hold some memory without releasing it.I think this link will help you to solve your issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top