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

Scene not getting garbage collected

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: fx2.1
    • Fix Version/s: 7u6
    • Component/s: javafx
    • Environment:

      Win7 Pro, JDK 7, JavaFX2.1

      Description

      When creating a new Scene() and replacing a previous Scene on the Stage with this new Scene the old scene is not getting garbage collected.
      This small app below gives me an OutOfMemory exception after pressing the "Create New" button 3-4 times. For testing i set: -Xms10m -Xmx16m
      There is no reference anymore to the previous scene. Why does GC not remove the unfererenced objects ? In the profiler I see the Heap growing.
      [code]
      import java.util.Random;
       
      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.StackPane;
      import javafx.scene.paint.Color;
      import javafx.stage.Stage;
       
       
       
       
      public class TestFX extends Application {
       

      Stage pStage;
      Random randomGenerator = new Random();


      @Override
      public void start(Stage stage) throws Exception {

      pStage = stage;

      Platform.runLater(new Runnable() {
      public void run() {

      StackPane stack = new StackPane();
      stack.setPrefWidth( 640);
      stack.setPrefHeight( 480);
      stack.setAlignment( Pos.TOP_LEFT);


      for (int i=0; i<100;i++){
      Button but = new Button("Button " + i);
      int randomX = randomGenerator.nextInt( 620);
      int randomY = randomGenerator.nextInt( 470);
      but.setTranslateX( randomX);
      but.setTranslateY( randomY);
      stack.getChildren().add( but);
      }



      Button makeNewButton = new Button("Make new");
      makeNewButton.setStyle("-fx-font: 22 arial; -fx-base: #b6e7c9;");
      makeNewButton.setOnAction( new EventHandler<ActionEvent>() {
      @Override
      public void handle(ActionEvent arg0) {
      try {
      start( pStage);
      } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      }
      });

      BorderPane border = new BorderPane();
      border.setTop( makeNewButton);
      border.setCenter( stack);
      Scene scene = new Scene( border, 640, 480, Color.WHITESMOKE);

      pStage.setScene( scene);
      pStage.show();
      }
      });

      }

       
      public static void main(String[] args) throws Exception{
              Application.launch(args);
          }
       
      }
       
      [/code]

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                lnerad Ľubomír Nerád
                Reporter:
                duke J. Duke (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported: