Closed GoogleCodeExporter closed 8 years ago
Yes, this is normal. As indicated in the README.txt file, you should call
IplImage.release() to release manually an IplImage create with one of the
IplImage.create*() factory method, if you do not want to wait for the garbage
collector, *not* cvReleaseImage(). If the IplImage is created by something
else, such as cvLoadImage(), then we need to call cvReleaseImage() on it, yes,
that is correct.
Original comment by samuel.a...@gmail.com
on 10 Feb 2012 at 5:08
Yes, thanks, you are right, I have tried with image.release(); instead of line
(5) and it works.
However it was not clear from the README.txt that I can leave the memory
deallocation to the garbage collector or I can call image.release() explicitly
_BUT_ I cannot call cvReleaseImage(image). Anyway checking opencv_core.java I
see that release() calls deallocate() which calls cvReleaseImage() (after
create() created a deallocator) so based on the source I see no difference
between release() and cvReleaseImage(). Can you explain what I am missing?
Thanks.
Original comment by ricsi.sz...@gmail.com
on 10 Feb 2012 at 8:28
When calling cvReleaseImage(), since it is just a normal function, JavaCV has
no way of knowing that memory has been released, so the garbage collector will
try to rerelease it again once its reference goes out of scope. That's when the
crash happens.
I could create a special cvReleaseImage() function and make it behave
differently from the original cvReleaseImage(), but what's the point? Makes
more sense to name it differently, thus IplImage.release()...
I guess I should add a warning about that in the README.txt file in any case,
will do, thanks!
Original comment by samuel.a...@gmail.com
on 10 Feb 2012 at 11:58
Thank you for the help and the explanation!
Original comment by ricsi.sz...@gmail.com
on 10 Feb 2012 at 12:03
Is my unterstanding of the the working of cvLoadImage vs IplImage.create*
correct?
1) cvLoadImage allocates some memory outside of the java heap memory which has
to be explicitely released by cvReleaseImage or we will have a memory leak
where the java process finally eats up all the available memory
2) The factory methods IplImage.create* will create an image wich image data
stored in the java heap space and will be garbage collected as any "normal"
java object. If I call cvRelease on such an image, than the allocated memory
will be released immediately??
I have implemented a web application using cvLoadImage to load an IplImage and
I wrap it with an OpenCVImage class. In the finalizer of this class I call
cvReleaseImage. Is this correct? I notice, that the java process memory will
grow much beyond the max heap setting -Xmx. I would like to prevent the
application to use to much memory on the system
I would be glad if you could explain how the memory management works.
Thanks a lot
Rolf
Original comment by rolf....@gmail.com
on 4 Dec 2012 at 8:14
@rolf If you're comfortable with cvCreateImage(), cvLoadImage(), and
cvReleaseImage(), just use that, they will behave exactly as expected from the
documentation of the C API. IplImage.create*() allocate memory in the same
exact way, but also register a deallocator (something like a finalizer), that
is all. If you want to release the memory and the deallocator, call
IplImage.release(), do not call cvReleaseImage(), because this does not
releases the deallocator. Is this clear? About the Java heap, that has nothing
to do with either OpenCV or JavaCV, they do not touch it, so please refer to
the documentation of Java.
And please post your questions on the mailing list next time if possible, thank
you.
Original comment by samuel.a...@gmail.com
on 5 Dec 2012 at 1:20
Original issue reported on code.google.com by
ricsi.sz...@gmail.com
on 9 Feb 2012 at 4:22