Ask Your Question
1

Destroy Java 'Mat'-Object

asked 2013-06-05 06:33:08 -0500

keltik gravatar image

I am using OpenCV in Java. Is there a method that destroys a Mat object (deletes it from memory)?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-06-05 08:49:37 -0500

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.

edit flag offensive delete link more

Comments

1

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.

Steven P. Goldsmith gravatar imageSteven P. Goldsmith ( 2015-05-11 19:30:40 -0500 )edit
1

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.

noamgot gravatar imagenoamgot ( 2018-01-08 02:07:51 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-06-05 06:33:08 -0500

Seen: 3,189 times

Last updated: Jun 05 '13