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

SwingNode Memory Leak

XMLWordPrintable

    • x86_64
    • generic

      A DESCRIPTION OF THE PROBLEM :
      If I Open a new Stage with a SwingNode and close it. The SwingNode stays in the Heap but it isn't reachable anymore.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Open a new Window with the Button
      Close the Window with X

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The SwingNode is not reachable anymore and should be disposed
      ACTUAL -
      The SwingNode stays in the heap and is never disposed

      ---------- BEGIN SOURCE ----------
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.JButton;
      import javax.swing.SwingUtilities;

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.embed.swing.SwingNode;
      import javafx.scene.Scene;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      /**
       *
       */
      public class JFXDemo extends Application {

      Stage stage;

      /**
      * @param args
      */
      public static void main( final String[] args ) {
      launch( args );
      }

      @SuppressWarnings("restriction")
      @Override
      public void start( final Stage stage ) {
      final SwingNode swingNode = new SwingNode();

      createSwingContent( swingNode );

      final StackPane pane = new StackPane();
      pane.getChildren().add( swingNode );

      stage.setTitle( "Swing in JavaFX" );
      stage.setScene( new Scene( pane, 250, 150 ) );
      stage.show();
      }

      private void createSwingContent( final SwingNode swingNode ) {
      SwingUtilities.invokeLater( new Runnable() {
      @Override
      public void run() {
      final JButton button = new JButton( "Click" );
      button.addActionListener( new ActionListener() {

      @Override
      public void actionPerformed( final ActionEvent e ) {

      final SwingNode swingNode = new SwingNode();

      createSwingContent( swingNode );

      final StackPane pane = new StackPane();
      pane.getChildren().add( swingNode );
      Platform.runLater( () -> {
      new Runnable() {
      @Override
      public void run() {
      Stage myStage;
      myStage = new Stage();
      myStage.setTitle( "Swing in JavaFX" );
      myStage.setScene( new Scene( pane, 250, 150 ) );
      myStage.show();

      }
      }.run();
      } );

      }
      } );
      swingNode.setContent( button );

      }
      } );
      }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        1. SwingNodeSetContentMemoryLeakTest.java
          5 kB
        2. JFXDemo.java
          2 kB
        3. jdk.patch
          7 kB
        4. fx.patch
          4 kB

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: