Using Processing, I am working on a project that pairs video clips and strings from a txt file at random. Whenever I run the program, eventually it stops and I receive a mess of the same error:
JNA: Callback org.gstreamer.elements.AppSink$3@1bf404f threw the
following exception: java.lang.OutofMemoryError: Java heap space
I am suspecting that there is a memory leak with how I am handling the creation and deallocation of my Movie object, but I can't figure out what's wrong. setup()
is where I first instantiate the Movie object in order to prep for the first iteration. In my draw()
, to me it looks like I am resetting the Movie object to null each time before instantiating it again, which to my mind should take care of the memory issue but that does not seem to be the case.
Can anyone provide a solution? In my preferences, I do have my memory increased to 256 MB but I know that increasing the memory only delays the inevitable error. Thank You!
Here is my code:
import processing.video.*;
PFont font;
String[] posts; // strings loaded in setup()
String[] videos = {"1a.mov", "2a.mov", "3a.mov", "4a.mov", "5a.mov", "6a.mov",
"7a.mov", "8a.mov", "9a.mov"}; // video clips
String post;
Post first; // First post
Post p; // Next iteration of posts
Movie myMovie;
String clip;
int count; // Iteration counter
int a = 0; // image()
float duration = 0; // Movie duration
float time = 0; // Movie time
void setup(){
size(displayWidth, displayHeight);
background(0);
posts = loadStrings("posts.txt"); // load strings from file
font = loadFont("HelveticaNeue-Bold-48.vlw"); // load font
post = posts[int(random(posts.length))]; // use random post
textFont(font); // Set text font
textSize(50);
textAlign(CENTER);
fill(255, 248, 43); // Yellow fill
if (frame != null){
frame.setResizable(true); // resizable window
}
/** Random generation of initial clip and post */
clip = videos[int(random(videos.length))];
myMovie = new Movie(this, clip);
makeTint();
myMovie.play();
count++;
first = new Post(post);
println("Playing clip: " + clip + " w/ post: " + "\"" + post + "\"");
println("Iteration: " + count + "\n");
}
/** Will generate random clips and posts after initial clip **/
void draw(){
if (a == 0){
image(myMovie, 0, 0);
}
image(myMovie, 0, 0);
duration = myMovie.duration();
time = myMovie.time();
/** If clip is at end **/
if ((duration - time) < 0.1){
first = null; // Remove first post
/** Reset clip **/
clip = null;
myMovie = null;
clip = videos[int(random(videos.length))];
myMovie = new Movie(this, clip);
count++;
makeTint();
myMovie.play();
/** Reset post **/
p = null;
post = posts[int(random(posts.length))];
println("Playing clip: " + clip + " w/ post: " + "\"" + post + "\"");
println("Post length: " + post.length());
println("Iteration: " + count + "\n");
}
p = new Post(post);
}
/** Method needed to play clips **/
void movieEvent(Movie m){
m.read();
}
/** Class for displaying post **/
class Post{
/*******************************************\
* Function: Post Object Constructor
* Parameter Description:
*-----------------------------------------
* t, text to display
\*******************************************/
Post(String t){
text(t, width/2, height - 150);
}
}