nazirmohd2006 / javacv

Automatically exported from code.google.com/p/javacv
0 stars 0 forks source link

Memmory leaks in big loops #355

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Creating big loops inside which we allocate some objects which aren't 
IplImages or CvMat's (- e.g CvMatArray)

What is the expected output? What do you see instead?
I expect working program without memory leaks. I get memory leaks, because I 
can't find any ways to release objects creating inside loop.

What version of the product are you using? On what operating system?
OpenCV 2.4.5 and appropriate JavaCv .jars. System: Win7 x64.

Please provide any additional information below.

Example code which causes memory leaks can looks like that:
 for(int i=0;i<100000;i++){
        CvMatArray array=new CvMatArray(); //or new CvScalar() or  
                                           //something else 
    //How to deallocate array here If I don't want to get memory leaks?                     
        }

In case of IplImages or CvMat's I can use pairs: .create() and .release() 
methods
inside big loops and thanks that I can regularly release memory. But what about 
other objects like e.g CvMatArray, CvSalars etc. ? Is there any way to release 
them?

Original issue reported on code.google.com by mirkro...@gmail.com on 28 Aug 2013 at 9:45

GoogleCodeExporter commented 8 years ago
Sure, we should be able to call release() on them as well.

Original comment by samuel.a...@gmail.com on 28 Aug 2013 at 9:55

GoogleCodeExporter commented 8 years ago
First of all: Thank you for incredible fast reply :). And the second thing: 
So maybe it's strange question, but how can I invoke release() method on them?

This code:
 CvMatArray array=new CvMatArray();
  array.release();
  CvScalar scalar=new CvScalar();
 scalar.release();
doesn't work...

Original comment by mirkro...@gmail.com on 28 Aug 2013 at 10:26

GoogleCodeExporter commented 8 years ago
Have you also tried to call System.gc() after release() to make sure that the 
garbage collector actually runs to release memory taken by Java?

Original comment by samuel.a...@gmail.com on 28 Aug 2013 at 10:29

GoogleCodeExporter commented 8 years ago
No I haven't and after some tests I see that it's good idea :).
In this case:
  for(int i=0;i<100000000;i++){
      CvMatArray array=new CvMatArray();                              
      CvScalar scalar=new CvScalar();      
      System.gc();
   }
I don't have memory leaks. I noticed also that if I write something like that:
   for(int i=0;i<100000000;i++){
      IplImage array=IplImage.create(zmieniane.cvSize(), 8, 1);
       array.release();
       System.gc();
     }
I HAVE TO also use System.gc() even although I used .release().
Anyway, problem is solved. Thanks for help.

Original comment by mirkro...@gmail.com on 28 Aug 2013 at 11:04

GoogleCodeExporter commented 8 years ago
Good! Please ask your questions on the mailing list next time if possible, 
thanks!

Original comment by samuel.a...@gmail.com on 31 Aug 2013 at 7:06