Destroy Java 'Mat'-Object
I am using OpenCV in Java. Is there a method that destroys a Mat object (deletes it from memory)?
From the Java docs under core librarie and Mat I have found this:
If you want to release the data pointed by a array header before the array destructor is called, use Mat.release().
However, a destructor is called automatically when a create object reaches the end of its scope. So basically if you do not want to release your object memory explicitly, you do not have to call this.
See How to check for native memory leaks as an unpatched OpenCV 2.4.x or 3.0.0-dev will leak native memory since it relies on the finalize method which is generally bad practice. There's no guarantee if or when it will be called. I patch the Java source before and after compile to get access to the delete method which frees native memory.
Just in case someone reaches here - it seems like the best practice is to call release()
on your Mat
object in the moment you don't need it anymore - waiting until the end of the scope/function/program can cause out-of-memory exceptions, or even just a massive slow-down of your app. see this for more details.
Asked: 2013-06-05 06:33:08 -0600
Seen: 4,832 times
Last updated: Jun 05 '13