Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although the DropHandler is not removed from the static AppContext map, that is not really the root cause, but merely one of the causes in the chain. (The drop handler is intended to be a singleton, and not cleared up until the AppContext class is unloaded, which in practice is never.) Use of a singleton DropHandler is by design.</p> <p>The real cause of the leak is that the DropHandler sets up an instance of TransferSupport, that is reused for each DnD operation, and during a DnD operation, provides it with a reference to the component involved in DnD. The problem is that <strong>it does not clear the reference when DnD finishes</strong>. If the DropHandler called <code>TransferSupport.setDNDVariables(null,null)</code> when the DnD exited, then the problem would go away. This is also the most logical solution, since the reference to the component is only required while DnD is in progress. Other approaches, such as clearing the AppContext map are circumventing the design rather than fixing a small oversight.</p> <p>But even if we fix this, the frame would still not be collected. Unfortunately, there appears to be another problem: When I commented out all the DnD related code, reducing to just a simple JFrame, this too was not being collected. The retaning reference was in <code>javax.swing.BufferStrategyPaintManager</code>. There is a <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6575402" rel="nofollow noreferrer">bug report</a> for this, as yet unfixed.</p> <p>So, if we fix the DnD, we hit another retention problem with repainting. Fortunately, all of these bugs hold on to only one frame (hopefully the same one!), so it is not as bad as it could be. The frame is disposed, so native resources are released, and all content can be removed, allowing that to be freed, reducing the severity of the memory leak.</p> <p>So, to finally answer your question, you are not doing anything wrong, you are just giving some of the bugs in the JDK a little air time!</p> <p><strong>UPDATE:</strong> The repaint manager bug has a quick fix - adding</p> <pre><code>-Dswing.bufferPerWindow=false </code></pre> <p>To the jvm startup options avoids the bug. With this bug quashed, it makes sense to post a fix for the DnD bug:</p> <p>To fix the DnD problem, you can add a call to this method at the end of importData().</p> <pre><code> private void cancelDnD(TransferSupport support) { /*TransferSupport.setDNDVariables(Component component, DropTargetEvent event) Call setDNDVariables(null, null) to free the component. */ try { Method m = support.getClass().getDeclaredMethod("setDNDVariables", new Class[] { Component.class, DropTargetEvent.class }); m.setAccessible(true); m.invoke(support, null, null); System.out.println("cancelledDnd"); } catch (Exception e) { } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload