0

I have a memory leak problem using the cvCopy function of OpenCV. If I comment that line it's all ok. If not the memory raises until the system crashes..

I've found this interesting article about OpenCV memory leaks: http://www.andol.info/hci/963.htm but if I comment the line: targetImage = cvCreateImage( ....

I get another problem because it says that I'm passing a null pointer.

..... //other code (here we are inside a loop
cvSetImageROI(&tmpimag,TargetRect);
targetImage = cvCreateImage( cvSize(TargetRect.width, TargetRect.height), tmpimag.depth, tmpimag.nChannels );
cvCopy(&tmpimag,targetImage);
cvResetImageROI(&tmpimag); // release image ROI 
....//other code

2 Answers 2

3

For what I can tell based on your little snippet of code, the mem leak might be your fault.

On each iteration of the loop you are creating/allocating a new image with cvCreateImage(), but I don't see you releasing it (check cvReleaseImage()). Therefore, after each iteration, more and more memory is allocated generating a genuine mem leak.

EDIT:

cvResetImageROI(&tmpimag); does not release an image, it just resets the ROI information previously set. You still need to cvReleaseImage(&tmpimag).

5
  • I'm releasing it at the beginning of the loop
    – davan
    Apr 1, 2011 at 14:16
  • By the way which version are you using? Apr 1, 2011 at 14:24
  • FOUND THE MEMORY LEAK, it was not this cvCopy the problem! sorry and thank you very much for the hints
    – davan
    Apr 1, 2011 at 14:24
  • 1
    @davan It's important to us that you review the answers and either accept the one that solved your problem or vote up those that really helped you. Apr 1, 2011 at 14:33
  • @karlphillip I don't find the button to thank! I'm not registered so maybe it's that the reason.. could it be? I can't find neither the button to accept the answer..
    – davan
    Apr 1, 2011 at 14:35
0

are you releasing targetImage each time the loop iterates?

2
  • I'm releasing it at the beginning of the loop yes
    – davan
    Apr 1, 2011 at 14:17
  • FOUND THE MEMORY LEAK, it was not this cvCopy the problem! sorry and thank you very much for the hints
    – davan
    Apr 1, 2011 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.