What steps will reproduce the problem? 1. about 1000 images 2. run this function with getBufferedImage only (normalImage is global, it released and all about it is ok) What is the expected output? What do you see instead? I have 8G memory, the java program (with this function only) gradually consume 3Gb (it's like 300m-700m-400m-800m) and even after the program finished running successfully, the 3GB memory is still occupied (not by Java) What version of the product are you using? On what operating system? Ubuntu 10.04, OpenCV 2.3.1 without python and android support, jdk 1.6, Xmx1024m, Xms256m Please provide any additional information below. Reading images is ok, but this function have memory leak (normalImage is global, it released later in another function, there is no trouble with it): public void someFunction() { BufferedImage image = null; try { image = normalImage.getBufferedImage(); } finally { if(image != null) { image.flush(); image = null; } } } What am I doing wrong? I have this trouble always when I use getBufferedImage in my functions. Thank you.
Comment 1 by project member samuel.a...@gmail.com, Dec 29, 2011
Jan 14, 2012
, I was able to reproduce memory leak with following code. I am not sure if this is expected behavior of JNI but using cvReleaseImage() fixes the problem. Assigned variables within functions are not garbage collected. public static void main(String[] args) { for (int i = 0; i < 100000; i++) { IplImage someImage = getImage(); // causes memory leak // cvReleaseImage(someImage); // fixes memory leak } } public static IplImage getImage() { // IplImage normalImage = cvLoadImage("bg.bmp"); IplImage normalImage = cvCreateImage(cvSize(320, 240), IPL_DEPTH_8U, 3); return normalImage; }
Jan 24, 2012
, Yes that's normal, cvCreateImage() is nothing more than a normal C function. Use the IplImage.create() factory method if you want garbage collection behavior.
Feb 18, 2012
, Judging by the lack of feedback, I assume the issue has been resolved. Please let me know if this is not the case.
Status: Done