MCR 7.17 memory leak when used from Java
Show older comments
We recently shifted from MCR 7.10 to MCR 7.17 which has caused my Java program to die after being running for around 24 hours because all memory has been used.
After running a log of tests on both 7.10 and 7.17 I can see that especially when using advanced data structures, it seems that memory is not released when using disposeArray.
I made the following test program:
package com.test.matlab;
import com.mathworks.toolbox.javabuilder.MWArray;
import com.mathworks.toolbox.javabuilder.MWNumericArray;
public class MatlabMemoryLeakClient {
/**
* @param args
*/
public static void main(String[] args) {
try {
// Just to load javabuilder.jar so we know how much memory it uses
MWNumericArray init = new MWNumericArray(0);
MWArray.disposeArray(init);
System.out.println("Press ENTER when ready to go...");
// Wait for user to press enter
System.in.read();
for (int i=0; i < 5000; i++) {
final String[] FIELDS = new String[]{"Field1", "Field2", "Field3", "Field4"};
final int KMAX = 200;
MWStructArray data5 = new MWStructArray(1, KMAX, FIELDS);
for (int k=0; k < KMAX; k++) {
data5.set(FIELDS[0], k+1, new MWNumericArray(k*1.13));
data5.set(FIELDS[1], k+1, new MWNumericArray(k*9.48));
data5.set(FIELDS[2], k+1, new MWCharArray("TEST1" + k*9.48));
data5.set(FIELDS[3], k+1, new MWCharArray("TEST2" + k*9.48));
}
MWArray.disposeArray(data5);
System.out.println("MWStructArray. Run=<" + i + ">");
}
Thread.sleep(10 * 60 * 1000);
} catch (Throwable e) {
System.out.println("Error in matlab testing. Exception=<" + e);
}
}
}
I then ran it against MCR 7.10 and MCR 7.17
MCR 7.10 - When started and waiting for user to hit ENTER it used 15.708K memory. After hitting ENTER the memory continously grew until around 1.500 loops. Then it stayed on 31.984K for the following 3.500 loops.
MCR 7.17 - When started and waiting for user to hit ENTER it used 31.224K memory. After hitting ENTER the memory continued to grow, program crashed at 2525 loops (out of 5.000) with a memory usage at 527.304K.
WIth both MCR 7.10 and MCR 7.17 it seems that memory is not relased correctly. But the problem is much more severe with MCR 7.17.
Any ideas to what the problem might be, do I release the memory in a wrong way?
PS: I tried using the dispose command on the object itself also, but that makes no difference.
2 Comments
Walter Roberson
on 9 Jun 2012
This previous discussion might be relevant:
http://www.mathworks.com/matlabcentral/answers/39858-clearing-handle-subclasses-with-timer-objects
John Datson
on 9 Jun 2012
Accepted Answer
More Answers (0)
Categories
Find more on COM Component Integration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







