Package ptolemy.gui

Class MemoryCleaner


  • public class MemoryCleaner
    extends java.lang.Object
    Methods that clean up possible memory leaks caused by listeners. Experimental methods will be marked so in their javadoc comments until they are proven to be effective. The static methods of this class can be used to remove listeners when disposing of Windows. Swing, for various reasons, does not know when a window has been disposed and thus never garbage collects the listeners. These listeners each have a reference to the window which means the window (and everything it references) never gets garbage collected.
    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Aaron Schultz
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Red (cxh)
    • Constructor Summary

      Constructors 
      Constructor Description
      MemoryCleaner()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int removeActionListeners​(javax.swing.AbstractButton button)
      Remove ActionListeners from an AbstractButton (such as a JMenuItem.
      static int removeActionListeners​(javax.swing.JComponent component)
      Remove ActionMapListeners from a JComponent.
      static int removeActionListeners​(javax.swing.JMenuBar menubar)
      Remove ActionListeners from a JMenuBar.
      static int removeActionListeners​(javax.swing.JToolBar toolbar)
      Remove ActionListeners from a JToolBar.
      static int removeWindowListeners​(java.awt.Window window)
      Remove WindowListeners from a Window.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MemoryCleaner

        public MemoryCleaner()
    • Method Detail

      • removeActionListeners

        public static int removeActionListeners​(javax.swing.JMenuBar menubar)
        Remove ActionListeners from a JMenuBar.
        Parameters:
        menubar - The menubar from which the ActionListeners are to be removed.
        Returns:
        The number of listeners removed.
      • removeActionListeners

        public static int removeActionListeners​(javax.swing.AbstractButton button)
        Remove ActionListeners from an AbstractButton (such as a JMenuItem. If the AbstractButton is a JMenu, the ActionListeners of all the child items get removed too.
        Parameters:
        button - The button from which the ActionListeners are to be removed.
        Returns:
        The number of listeners removed.
      • removeActionListeners

        public static int removeActionListeners​(javax.swing.JComponent component)
        Remove ActionMapListeners from a JComponent. This is useful for removing key bindings.
        Parameters:
        component - The JComponent from which the Action in a ActionMap are to be removed.
        Returns:
        The number of listeners removed.
      • removeWindowListeners

        public static int removeWindowListeners​(java.awt.Window window)
        Remove WindowListeners from a Window. Experimental.
        Parameters:
        window - The Window from which WindowListeners are to be removed.
        Returns:
        The number of listeners removed.
      • removeActionListeners

        public static int removeActionListeners​(javax.swing.JToolBar toolbar)
        Remove ActionListeners from a JToolBar.
        Parameters:
        toolbar - The tool bar from which the ActionListeners are to be removed.
        Returns:
        The number of listeners removed.