You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by "kevin.le" <kl...@ashwireless.com> on 2016/07/29 13:53:15 UTC

[JAVA-Android]Memory Leak Investigation

Hi all, 

I am using a slightly modified version of QPID to communicate with Microsoft
Azure IoT Hub called proton-j-azure-iot-0.12.2.

So straight to the problem. I am investigating a memory leak when using a
HandlerThread class to post a task.

Here is the rough code snippet :



I've been reading a lot lately about Handler Thread so the structure above
was chosen because it takes care of Looper management.

So after running for 24 hours, the heap dump is run through Eclipse Memory
Analyzer and it suggests that the memory leak suspect is a lot of Thread not
being garbage collected. The heap increases 3MB after running roughly 16
hours. 

<http://qpid.2158936.n2.nabble.com/file/n7648353/thread.png> 
<http://qpid.2158936.n2.nabble.com/file/n7648353/suspect.png> 

It seems to me that the HandlerThread class implementation is correct (I
follow this:
https://blog.nikitaog.me/2014/10/11/android-looper-handler-handlerthread-i/
). And just by looking at the Dominator tree in MAT, it is not obvious where
the problem can be. 

I've been pulling my hair out and searching through StackOverflow on memory
leak problem regarding THread operation but haven't found any concrete
solution to this.

Has anybody come across this before or How can I find out where the problem
is given all the tools that I have (Android studio and MAT)?

Any help appreciated.
Many thanks for reading



--
View this message in context: http://qpid.2158936.n2.nabble.com/JAVA-Android-Memory-Leak-Investigation-tp7648353.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


RE: [JAVA-Android]Memory Leak Investigation

Posted by ad...@live.com.

PS: don't use nabble when you send a mail because half of it is missing when we receive it.


As for the Azure part, unfortunately I cannot help you because I never used it. Hopefully someone else will be able to.




On Fri, Jul 29, 2016 at 7:45 PM +0300, <ad...@live.com> wrote:







If A holds a reference to B and B holds a reference to A. Then you will get this cyclic tree when you open A.


Try opening the "referent" instead of the "runner" in the second image.



From: kevin.le

Sent: Friday, July 29, 18:53

Subject: RE: [JAVA-Android]Memory Leak Investigation

To: users@qpid.apache.org



Thanks for the quick reply Adel.


Tried your suggestion. Here are some screengrabs:


<http://qpid.2158936.n2.nabble.com/file/n7648365/thread-compare.png>


<http://qpid.2158936.n2.nabble.com/file/n7648365/reference-compare.png>


Looking at the second image, I could not understand it. The reference tree

jumps to and fro between two references forever if I open any of the tree.


What do you advise?






--

View this message in context: http://qpid.2158936.n2.nabble.com/JAVA-Android-Memory-Leak-Investigation-tp7648353p7648365.html

Sent from the Apache Qpid users mailing list archive at Nabble.com.


---------------------------------------------------------------------

To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org

For additional commands, e-mail: users-help@qpid.apache.org



RE: [JAVA-Android]Memory Leak Investigation

Posted by ad...@live.com.

If A holds a reference to B and B holds a reference to A. Then you will get this cyclic tree when you open A.


Try opening the "referent" instead of the "runner" in the second image.



From: kevin.le

Sent: Friday, July 29, 18:53

Subject: RE: [JAVA-Android]Memory Leak Investigation

To: users@qpid.apache.org



Thanks for the quick reply Adel.


Tried your suggestion. Here are some screengrabs:


<http://qpid.2158936.n2.nabble.com/file/n7648365/thread-compare.png> 


<http://qpid.2158936.n2.nabble.com/file/n7648365/reference-compare.png> 


Looking at the second image, I could not understand it. The reference tree

jumps to and fro between two references forever if I open any of the tree. 


What do you advise?






--

View this message in context: http://qpid.2158936.n2.nabble.com/JAVA-Android-Memory-Leak-Investigation-tp7648353p7648365.html

Sent from the Apache Qpid users mailing list archive at Nabble.com.


---------------------------------------------------------------------

To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org

For additional commands, e-mail: users-help@qpid.apache.org



RE: [JAVA-Android]Memory Leak Investigation

Posted by "kevin.le" <kl...@ashwireless.com>.
Thanks for the quick reply Adel.

Tried your suggestion. Here are some screengrabs:

<http://qpid.2158936.n2.nabble.com/file/n7648365/thread-compare.png> 

<http://qpid.2158936.n2.nabble.com/file/n7648365/reference-compare.png> 

Looking at the second image, I could not understand it. The reference tree
jumps to and fro between two references forever if I open any of the tree. 

What do you advise?





--
View this message in context: http://qpid.2158936.n2.nabble.com/JAVA-Android-Memory-Leak-Investigation-tp7648353p7648365.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


RE: [JAVA-Android]Memory Leak Investigation

Posted by Adel Boutros <ad...@live.com>.
Hi Kevin,
For an object to be GCed, no other object should hold reference to it. So you need to know who is holding a reference to the object which you suspect is leaking.To do so in Eclipse Memory analyzer, right-click any object in the tree, select "List object --> with incoming references". If you expand the tree, you will find out with object is holding a reference to your object recursively. Then you have to read the code to find out if it is really leaking.
What you can also do is take a heap dump at the start, another one at the end and compare the objects in the "histogram" view.
This is what I usually do.
Regards,Adel 

> Date: Fri, 29 Jul 2016 06:53:15 -0700
> From: kl@ashwireless.com
> To: users@qpid.apache.org
> Subject: [JAVA-Android]Memory Leak Investigation
> 
> Hi all, 
> 
> I am using a slightly modified version of QPID to communicate with Microsoft
> Azure IoT Hub called proton-j-azure-iot-0.12.2.
> 
> So straight to the problem. I am investigating a memory leak when using a
> HandlerThread class to post a task.
> 
> Here is the rough code snippet :
> 
> 
> 
> I've been reading a lot lately about Handler Thread so the structure above
> was chosen because it takes care of Looper management.
> 
> So after running for 24 hours, the heap dump is run through Eclipse Memory
> Analyzer and it suggests that the memory leak suspect is a lot of Thread not
> being garbage collected. The heap increases 3MB after running roughly 16
> hours. 
> 
> <http://qpid.2158936.n2.nabble.com/file/n7648353/thread.png> 
> <http://qpid.2158936.n2.nabble.com/file/n7648353/suspect.png> 
> 
> It seems to me that the HandlerThread class implementation is correct (I
> follow this:
> https://blog.nikitaog.me/2014/10/11/android-looper-handler-handlerthread-i/
> ). And just by looking at the Dominator tree in MAT, it is not obvious where
> the problem can be. 
> 
> I've been pulling my hair out and searching through StackOverflow on memory
> leak problem regarding THread operation but haven't found any concrete
> solution to this.
> 
> Has anybody come across this before or How can I find out where the problem
> is given all the tools that I have (Android studio and MAT)?
> 
> Any help appreciated.
> Many thanks for reading
> 
> 
> 
> --
> View this message in context: http://qpid.2158936.n2.nabble.com/JAVA-Android-Memory-Leak-Investigation-tp7648353.html
> Sent from the Apache Qpid users mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>