Today I fixed a memory bug in one of my programs. Albeit I always release memory cvReleaseImage after allocating it with cvCreateImage, memory consumption was enormous. Commenting out some of the source code quickly showed the responsible code fragments. Using cvCreateImage and afterwards cvCloneImage made it impossible to release the initially allocated memory. Therefore after some iterations (depending on your main memory) this program will crash. To fix this issue simply replace the cvCloneImage with cvCopy.

Bad code:

DO
 img2 = cvCreateImage(cvSize(img->width, img->height), img->depth, img->nChannels);
[...]
 img = cvCloneImage(img2);
 cvReleaseImage(&img2);
LOOP

Good code:

DO
 img2 = cvCreateImage(cvSize(img->width, img->height), img->depth, img->nChannels);
[...]
 //img = cvCloneImage(img2);
 cvCopy(img2,img,NULL);
 cvReleaseImage(&img2);
LOOP

Last Updated (Thursday, 08 July 2010 21:54)

 

Add comment


Security code
Refresh

Sponsored links: