We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › minim AudioRecorder memory leak and crash
Page Index Toggle Pages: 1
minim AudioRecorder memory leak and crash (Read 936 times)
minim AudioRecorder memory leak and crash
Dec 19th, 2009, 2:54pm
 
Hi,
I found a memory leak in AudioRecorder in minim. Quite large actually.
Repeatedly creating and deleting AudioRecorder instances crashes the applet in 30 seconds with a OutOfMemoryError error.
One of my apps was crashing on OutOfMemoryError, and I hunted down the cause of the problem on the repetitive AudioRecorder creations.

I don't know where to file bug reports for minim, so I do it here, which is not the best place I agree. Any advice welcome...

Sample code to reproduce :

/* This app shows that there is a memory problem in AudioRecorder in buffered mode.
There is clearly a memory leak, as the used memory increases all the time.
GC tries to free memory all the time, but still used memory increases and finally crashes with a OutOfMemoryError error.
Changing the buffered mode to false reduces the problem, the memory fills up slower, but it still does. */
 
import ddf.minim.*;

Minim minim;

AudioRecorder recorder = null;
AudioInput in;


void setup() {
 size(512, 200, P2D);
 textMode(SCREEN);
 textFont(createFont("SanSerif", 12));

 minim = new Minim(this);
 in = minim.getLineIn(Minim.STEREO, 2048);
}

void stop() {
 // always close Minim audio classes when you are done with them
 in.close();
 if (recorder != null) {
   recorder.endRecord();
   recorder = null;
 }
 minim.stop();
 
 super.stop();
}

void draw() {
 /* Commenting out the following line fixes the memory problem, so the AudioRecorder is the problem, or at least it seems.. */
 recorder = minim.createRecorder(in, "snd.wav", true);
 
 // display memory
 background(0);
 float freemem = Runtime.getRuntime().freeMemory();
// float maxmem = Runtime.getRuntime().maxMemory();
 float allocmem = Runtime.getRuntime().totalMemory();
 float usedMem = allocmem-freemem;
 float rat = usedMem/allocmem;
 stroke(0,255,0);
 fill(0,255,0);
 text("Memory used ="+str(int(usedMem/1000000))+"Mb alloced mem="+str(int(allocmem/1000000))+"Mb", 100, 100);
 rect(10, int(200*(1. - rat)) , 10, int(200*rat));

}
Re: minim AudioRecorder memory leak and crash
Reply #1 - Jan 7th, 2010, 11:47pm
 
Any reason you have to create a recorder every time you run draw? Draw runs 60 times in a second by default if I'm not wrong. What are you trying to accomplish with your code? Unless you want a new recorder every 1/60 of a second you are just making a worm-like virus out of minim. I'm not sure about how the Java garbage collector works but it may not work as fast as you create and abandon objects so you may run out of memory.
Page Index Toggle Pages: 1