Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Memory Leak when loading new video file #20

Open
maxhaesslein opened this issue Nov 6, 2016 · 2 comments
Open

Memory Leak when loading new video file #20

maxhaesslein opened this issue Nov 6, 2016 · 2 comments
Labels

Comments

@maxhaesslein
Copy link

Hi there,

I have this simple test case:

// put at least two mp4 files in the data/ directory of this sketch

import gohai.glvideo.*;
import java.io.File;

GLMovie movie;

String movieNames[] = {};
int currentMovieIndex;
int time;

void settings() {
	size( 640, 480, P2D );
}

void setup() {

	// read all .mp4 files from data directory
	File dir = new File(dataPath(""));
	File[] files = dir.listFiles();
	for( int i=0; i < files.length; i++ ){
		String path = files[i].getAbsolutePath();
		if( path.toLowerCase().endsWith(".mp4") ) movieNames = append( movieNames, path );
	}

	// load the first movie
	println( "load first movie" );
	movie = new GLMovie( this, movieNames[0] );
	movie.loop();

	time = millis();

}

void draw() {

	// load new movie every 5 seconds
	if( time > 0 && millis() > time + 5000 ) {

		// try to free memory; nothing of this seems to work
		g.removeCache( movie );
		movie.close();
		movie = null;
		System.gc();

		// load next movie
		++currentMovieIndex;
		if( currentMovieIndex >= movieNames.length ) currentMovieIndex = 0;
		String newMovieName = movieNames[ currentMovieIndex ];
		println( "load movie '" + newMovieName + "'" );
		movie = new GLMovie( this, newMovieName );
		movie.loop();

		time = millis();
	}

	// display movie on screen
	if( movie.available() ) movie.read();
	background(0);
	image( movie, 0, 0, width, height );

}

a video is displayed and every 5 seconds the video is replaced with a new video. I'm running this on a Mac and in Activity Monitor I can see an increase in the memory every time a new video loads. After a few minutes, the framerate drops and videoplayback gets chunky.

I'm running this on Processing 3.2.2 with GL Video 1.1.

I'm not that experienced in processing or java, so I don't know how I can debug and fix this issue. Can someone help me out here?

@gohai
Copy link
Owner

gohai commented Nov 11, 2016

You might want to try and see if the native Java_gohai_glvideo_GLVideo_gstreamer_1close function (written in C) leaves any memory around, or if there is something the reference counting is overlooking.

But to be hontest, at this point, the priority is to get the library running well across all OS, and most users probably won't spawn new instances every 5 seconds. You might want to try concatenating your video files into one long file and simply use jump() to change the current playback position.

@gohai gohai added the bug label Nov 11, 2016
@gohai gohai changed the title Memory Leak when loading new video file? Memory Leak when loading new video file Nov 11, 2016
@gohai
Copy link
Owner

gohai commented Nov 23, 2017

See also this forum post

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants