View unanswered posts | View active topics It is currently Thu Mar 23, 2017 11:10 pm



Reply to topic  [ 5 posts ] 
 Memory leak 
Author Message

Joined: Wed Apr 18, 2012 10:59 pm
Posts: 2
Post Memory leak
Hi Mikael,
We're seeing a memory leak - I've narrowed it down to MigLayout (swapping to BorderLayout and there's no leak).
I'm working on a reproducible test case - I believe it is because the layout is used in a dialog that we repeatedly pop up and dispose. Does that sound like a possible reason?

Anyway, attached is an image of a memory dump for a leaked instance - we can see the remaining reference from the component down to the static map in Grid.
What action or actions normal clears this chain from the component to the Grid's map?

Also, we see a WeakHashMap is used to store layouts in Grid. In a WeakHaskMap only the keys are weak, did you consider using a map for weak values too? - just an idea.

Thanks.


Attachments:
Miglayout leak.png
Miglayout leak.png [ 43.47 KiB | Viewed 9074 times ]
Thu Apr 19, 2012 12:15 am
Profile
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Memory leak
Hello,

Thanks for the bug report. I have put this in the queue for the next version.

Cheers,
Mikael


Fri Apr 20, 2012 12:16 am
Profile WWW

Joined: Wed Apr 18, 2012 10:59 pm
Posts: 2
Post Re: Memory leak
OK, we worked it out:

The WeakHashMap in the Grid class is useless as a cache because it is trying to use a component as the weak key reference. However the component is held as a hard reference by the SwingComponentWrapper which is the 'value' in the map. So the key is never the final reference to the component because the value always holds a reference too.

This means entries in this map are never removed and every use of Miglayout leaks its components.

How come this hasn't been spotted before?
Looks like there is a check "Layout.isDesignTime()->Beans.isDesignTime()" for Grid to use this WeakHashMap. If this flag isn't on (which it isn't usually) then the map isn't used and this doesn't leak.

Apps which need Beans.setDesignTime(true), like ours, are leaking.

To test this, create run an app with Beans.setDesignTime(true), then add components to a MigLayout. Remove the components from layout and all references to them. Garbage Collect. Miglayout retains a reference.


Fri Apr 20, 2012 2:06 am
Profile
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Memory leak
Thanks for investigating. Looks like a brain fart om my account since I'm very aware of how weak references work. Sorry about that.

It will be fixed in the next version for sure.

Cheers,
Mikael


Fri Apr 20, 2012 5:31 pm
Profile WWW
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Memory leak
Hello,

This is fixed in the next version.
Sorry for the extreme delay.

Cheers,
Mikael


Fri Feb 22, 2013 2:44 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.