Memory Leak from iterating Opencv frames

前端 未结 5 2087
囚心锁ツ
囚心锁ツ 2020-12-14 20:20

I am using the java wrapper of OpenCV. I tried to write an Iterator over frames of a film. My problem is that the iterator is a huge memory leak. Here is a very simplified v

5条回答
  •  执念已碎
    2020-12-14 21:02

    I just want to add my $0.02 as I bumped into this issue when writing an application that will run for a long.

    Mat.release() is called automatically when the Java Mat-wrapper is garbage collected. However, since the Java wrapper is very small compared to the natively allocated object, it might not be garbage-collected fast enough.

    Therefore, you could either do Mat.release() when you know you are done with an object or call System.gc() at regular intervals to force removal of unused objects.

提交回复
热议问题