Antoine Schmitt
YaBB Newbies
Offline
Posts: 4
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)); }