[ 
https://issues.apache.org/jira/browse/PIVOT-861?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13581792#comment-13581792
 ] 

Roger Whitcomb edited comment on PIVOT-861 at 2/20/13 12:17 AM:
----------------------------------------------------------------

Part of PIVOT-861:  Lingering memory leak of ListenerList$Node objects when 
continuosly
creating and destroying windows or buttons (from BXMLSerializer).

It seemed like the basic problem was every time you use a ButtonRenderer, there 
is a
call to ImageView.setIcon which takes the old image out of the ImageViewSkin 
listener
list and puts the new one in, ending up creating a huge number of 
ListenerList$Node
objects for every add to these lists.

So, I rewrote the whole of ListenerList to use a small array for these lists 
instead
of a real linked list.  Empirically the lists don't usually grow very big, so 
the
default size of 5 works well except for a handful of cases, and then the largest
seen was 25.

The result is that I don't see any long-term memory leak at all in the test 
applications
and the overall memory thrashing seems less because we're creating far fewer of 
these
little Node objects (just to add and remove a reference in a small list).

Also reverted the last changes to ButtonData.java and Image.java to take out the
earlier workaround that wasn't quite working.

[branches/2.0.x]:
Sending        core\src\org\apache\pivot\util\ListenerList.java
Sending        wtk\src\org\apache\pivot\wtk\content\ButtonData.java
Sending        wtk\src\org\apache\pivot\wtk\media\Image.java
Transmitting file data ...
Committed revision 1447977.

[trunk]:
Sending        .
Sending        core\src\org\apache\pivot\util\ListenerList.java
Sending        wtk\src\org\apache\pivot\wtk\content\ButtonData.java
Sending        wtk\src\org\apache\pivot\wtk\media\Image.java
Transmitting file data ...
Committed revision 1447978.
                
      was (Author: rwhitcomb):
    Part of PIVOT-861:  Lingering memory leak of ListenerList$Node objects when 
continuosly
creating and destroying windows or buttons (from BXMLSerializer).

It seemed like the basic problem was every time you use a ButtonRenderer, there 
is a
call to ImageView.setIcon which takes the old image out of the ImageViewSkin 
listener
list and puts the new one in, ending up creating a huge number of 
ListenerList$Node
objects for every add to these lists.

So, I rewrote the whole of ListenerList to use a small array for these lists 
instead
of a real linked list.  Empirically the lists don't usually grow very big, so 
the
default size of 5 works well except for a handful of cases, and then the largest
seen was 25.

The result is that I don't see any long-term memory leak at all in the test 
applications
and the overall memory thrashing seems less because we're creating far fewer of 
these
little Node objects (just to add and remove a reference in a small list).

Also reverted the last changes to ButtonData.java and Image.java to take out the
earlier workaround that wasn't quite working.

Sending        core\src\org\apache\pivot\util\ListenerList.java
Sending        wtk\src\org\apache\pivot\wtk\content\ButtonData.java
Sending        wtk\src\org\apache\pivot\wtk\media\Image.java
Transmitting file data ...
Committed revision 1447977.
                  
> Memory leak: Window icon ImageListenerList retains reference to closed 
> windows, preventing garbage collection
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: PIVOT-861
>                 URL: https://issues.apache.org/jira/browse/PIVOT-861
>             Project: Pivot
>          Issue Type: Bug
>          Components: wtk, wtk-media
>    Affects Versions: 2.0.2
>         Environment: Windows XP, Java 1.7.0_05
>            Reporter: David Keen
>            Assignee: Sandro Martini
>             Fix For: 2.0.3
>
>         Attachments: leaktest.zip, Pivot861.launch, PivotSample.zip
>
>
> When a window or dialog is opened which has an icon, after it is closed it 
> cannot be garbage collected because a reference is retained to it through the 
> icon.  Removing the icon resolves the issue.
> As far as I've investigated, the issue appears to the in the 
> ImageListenerList which each Image contains.  I've done a heapdump of my 
> application and used the IBM HeapAnalyzer which shows this list containing a 
> reference to the window/dialog through the ImageViewSkin, but I don't know 
> the Pivot internals well enough to see where or how it should be released.
> I'll attach a simple test application to show the issue.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to