2 Replies Latest reply on Nov 8, 2011 6:13 PM by aidreamer

    Possible leak while playing video in a loop using JavaFX 2

      I have found a possible memory leak in the previous version of JavaFX 1.3.1 which I have pointed out [url https://forums.oracle.com/forums/thread.jspa?threadID=2192738]here
      None of the suggested hints helped me with this issue (but thanks for them anyway, i appreciate it). After the release of the new stable version of JavaFX (2.0) I have rewritten my small piece of code to test the behaviour once again.
      import javafx.application.Application;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.media.Media;
      import javafx.scene.media.MediaPlayer;
      import javafx.scene.media.MediaView;
      import javafx.stage.Stage;
      public class Main extends Application {
          private static final String MEDIA_URL = "file:///C:/vp6.flv";
          private MediaView mediaView = new MediaView();
           * @param args the command line arguments
          public static void main(String[] args) {
          public void start(Stage primaryStage) {
              primaryStage.setTitle("Video Try-out");
              Group root = new Group();
              Scene scene = new Scene(root, 300, 250);
          private void playVideo() {
              final MediaPlayer mediaPlayer = new MediaPlayer(new Media(MEDIA_URL));
              mediaPlayer.setOnEndOfMedia(new Runnable() {
                  public void run() {
      The application puts a MediaView instance on the stage and assigns a MediaPlayer instance to it. The MediaPlayer instance plays a local copy of some default oracle video file (available [url http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv]here) encoded as VP6. A new MediaPlayer instance is created and assigned to the MediaView each time an EndOfMedia - Event occurs. I'm setting the playback rate to 100.0 to achieve more cycles in a shorter time. The VM arguments for the run are "-Xms2m -Xmx32m" (I have also tried it without them which basically took just more time to get to the same result).

      This code performs the same as in the previous version of JavaFX which means that after an hour or two a one video frame stands still. Also if i use the built-in profiler in Netbeans, all the activity (allocation and garbage collection) stays at the same level. The "Live Profiling Results" window shows that the number of Live Objects of type "com.sun.media.jfxmediaimpl.NativeMediaPlayer" increases over time, but it doesn't happen 1-to-1 with each iteration of the player.

      Did anybody experience the same problem? Or could somebody please try to run the program?

      Thanks a lot