【发布时间】:2014-03-26 23:36:57
【问题描述】:
使用处理,我正在处理一个随机配对视频剪辑和来自 txt 文件的字符串的项目。每当我运行程序时,它最终都会停止,并且我会收到一堆相同的错误:
JNA:回调 org.gstreamer.elements.AppSink$3@1bf404f 抛出 以下异常:java.lang.OutofMemoryError: Java heap space
我怀疑我在处理 Movie 对象的创建和释放时存在内存泄漏,但我不知道出了什么问题。 setup() 是我首先实例化 Movie 对象以便为第一次迭代做准备的地方。在我的draw() 中,在我看来,我每次都将 Movie 对象重置为 null,然后再次实例化它,我认为这应该解决内存问题,但似乎并非如此。
谁能提供解决方案?在我的偏好中,我确实将内存增加到 256 MB,但我知道增加内存只会延迟不可避免的错误。谢谢!
这是我的代码:
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);
}
}
【问题讨论】:
标签: java memory memory-leaks processing heap-memory