-
Bug
-
Resolution: Fixed
-
P3
-
8u102
-
x86_64
-
windows_7
FULL PRODUCT VERSION :
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) Client VM (build 25.102-b14, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Windows 7 x64 - [Version 6.1.7601]
EXTRA RELEVANT SYSTEM CONFIGURATION :
Intel Core i7-4770K
8 GB RAM
NVIDIA GeForce GTX 760
A DESCRIPTION OF THE PROBLEM :
Native memory is leaked when many new MediaPlayer objects are created. It seems as though the memory leaks faster when the MediaPlayer is loading multiple files, opposed to a single file, however it still leaks if a single file is loaded into the MediaPlayer.
The Java heap is not leaking any memory.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program for a period of time, you will start to notice the native memory of the application increase. Eventually, the application will crash, as it cannot get any more memory from the OS. On my system, it takes anywhere from 30 minutes for an hour until it runs out of memory, but the leak is noticeable within a few minutes of running the program.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Application does not crash and will continue to play indefinitely.
ACTUAL -
Application will eventually crash, as it has run out of system (not heap) memory.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "EventThread" java.lang.OutOfMemoryError: unable to create new native thread
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;
import javafx.util.Duration;
import java.io.File;
public class MediaPlayerSample extends Application {
private static final String VIDEO_FOLDER_PATH = "C:/assets/";
private File[] files;
private int nextIdx;
private MediaPlayer mediaPlayer;
public static void main(String[] args) {
launch(args);
}
private void playNext() {
if (files == null || files.length == 0) {
return;
}
Media media = new Media(files[nextIdx++].toURI().toString());
if (nextIdx >= files.length) {
nextIdx = 0;
}
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.dispose();
}
mediaPlayer = new MediaPlayer(media);
mediaPlayer.setStopTime(new Duration(100));
mediaPlayer.setOnEndOfMedia(() -> playNext());
mediaPlayer.play();
}
@Override
public void start(Stage primaryStage) throws Exception {
File videoFolder = new File(VIDEO_FOLDER_PATH);
files = videoFolder.listFiles();
playNext();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None found.
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) Client VM (build 25.102-b14, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Windows 7 x64 - [Version 6.1.7601]
EXTRA RELEVANT SYSTEM CONFIGURATION :
Intel Core i7-4770K
8 GB RAM
NVIDIA GeForce GTX 760
A DESCRIPTION OF THE PROBLEM :
Native memory is leaked when many new MediaPlayer objects are created. It seems as though the memory leaks faster when the MediaPlayer is loading multiple files, opposed to a single file, however it still leaks if a single file is loaded into the MediaPlayer.
The Java heap is not leaking any memory.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program for a period of time, you will start to notice the native memory of the application increase. Eventually, the application will crash, as it cannot get any more memory from the OS. On my system, it takes anywhere from 30 minutes for an hour until it runs out of memory, but the leak is noticeable within a few minutes of running the program.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Application does not crash and will continue to play indefinitely.
ACTUAL -
Application will eventually crash, as it has run out of system (not heap) memory.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "EventThread" java.lang.OutOfMemoryError: unable to create new native thread
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;
import javafx.util.Duration;
import java.io.File;
public class MediaPlayerSample extends Application {
private static final String VIDEO_FOLDER_PATH = "C:/assets/";
private File[] files;
private int nextIdx;
private MediaPlayer mediaPlayer;
public static void main(String[] args) {
launch(args);
}
private void playNext() {
if (files == null || files.length == 0) {
return;
}
Media media = new Media(files[nextIdx++].toURI().toString());
if (nextIdx >= files.length) {
nextIdx = 0;
}
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.dispose();
}
mediaPlayer = new MediaPlayer(media);
mediaPlayer.setStopTime(new Duration(100));
mediaPlayer.setOnEndOfMedia(() -> playNext());
mediaPlayer.play();
}
@Override
public void start(Stage primaryStage) throws Exception {
File videoFolder = new File(VIDEO_FOLDER_PATH);
files = videoFolder.listFiles();
playNext();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None found.
- relates to
-
JDK-8186498 Native-Memory-Leak while playing video
-
- Closed
-