Remove finalize() for all Java classes (Bug #3846)


Added by Steven Goldsmith over 10 years ago. Updated almost 10 years ago.


Status:Done Start date:2014-08-06
Priority:Normal Due date:
Assignee:Steven Goldsmith % Done:

100%

Category:java bindings
Target version:3.0
Affected version:2.4.9 (latest release) Operating System:Linux
Difficulty:Medium HW Platform:x64
Pull request:

Description

It is generally considered bad practice to use finalize since there no guraentee if or when it will be called. When you build applications that process a lot of images you will end up with a lot of finalizers in the queue and it eventually will get backed up. Another side effect as is demonstrated by Mat is that it will consume large amounts of memory since n_delete is never called (calling Mat.release() is a work around). Instead there should be some type of public clean up method that deallocates native memory and not rely on finalize().

References:

https://plumbr.eu/blog/debugging-to-understand-finalizer
http://stackoverflow.com/questions/158174/why-would-you-ever-implement-finalize


Associated revisions

Revision daa99514
Added by Vadim Pisarevsky almost 10 years ago

Merge pull request #3846 from mshabunin:fix-headers

History

Updated by Steven Goldsmith over 10 years ago

This also affects 3.0.0 master branch.

Updated by Dmitry Retinskiy over 10 years ago

Steven,

if you could implement the correction it would be appreciated (see http://www.code.opencv.org/projects/opencv/wiki/How_to_contribute for details).

  • Status changed from New to Open
  • Assignee changed from Andrey Pavlenko to Steven Goldsmith

Updated by Steven Goldsmith almost 10 years ago

OK, sorry I didn't see this earlier. It's best to make gen_java.py generate proper clean up code. I'll see if I can get a submission in, thanks.

Updated by Steven Goldsmith almost 10 years ago

Added pull request: https://github.com/Itseez/opencv/pull/4006. Once that's accepted I'll fix the rest of the memory leaks and close this bug.

  • Target version set to 3.0

Updated by Steven Goldsmith almost 10 years ago

Pull request merged into master.

  • Status changed from Open to Done
  • % Done changed from 0 to 100

Updated by Steven Goldsmith almost 10 years ago

https://github.com/Itseez/opencv/pull/4014 made delete() method public instead of protected, so calling code can access.

Also available in: Atom PDF