Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4277356

JFrame memeory leak

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs

      The following was submitted as part of an evaluation of an unrelated bug by one of our Russian team members, Denis Mikhalikin, <###@###.###>. Since it reports a possible memory leak, I am submitting it as a separate bug:

      I found the chain that follows to static variable - appContext.
      JFrame <- OffscreenImage <- RepaintManager <- Hashtable$Entry <-
      Hashtable <- AppContext <- static appConext.
      All classes, except AppContext, are in swing library.

      I think this unfinalized static chain may lead to this memory leak.
      When i cut this link by removing RepaintManager through
      RepaintManager.setCurrentManager(null), the number of leaks is
      reduced to zero and some times to 1 (not yet gc`ed, i think) .


      OffscreenImage removed automaticaly via removeNotify if the component is

      JComponent:
      "
           // JComponent will inform us when it is no longer valid
           // (via removeNotify) we have no such hook to other components,
           // therefore we don't keep a ref to the Component
           // (indirectly through the Image) by stashing the image.
      "

      But JFrame is not JComponent.

      I think the procedure suggested in swing code for removing
      OffscreenImage is dangerous - it postpones the removing
      until next call to getOffscreenBuffer - in most cases until
      next redrawing. But when all J-components are
      removed and no JComponent available, the link
      would never be removed.

      RepaintManager.setCurrentManager(null) removes OffscreenImage at once.
      So i suggest to call this method in removeNotify - same as in JComponent

      to remove link.

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            hgajewsksunw Hania Gajewska (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: