cvReleaseImage

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

cvReleaseImage

rohlik
Hi guys. I've got a problem with releasing my images - apparently I'm doing something wrong, but I can't discover what it is. My program takes more and more memory and doesn't free it, until I close it. So I have to resize images and make them smaller to be able to do something at all, but I'm still really not happy with it :) So here's what my program looks like:

#include ...
 //some including
IplImage* src, *hue, *saturation, *value, *red, *green, *blue, *gray;
 //there are more images than these
int x; double y; ...
 //some declarations
 
char *names[] = { "0101.jpg", "0102.jpg", "0103.jpg", "0104.jpg", 0 };
 //again, there are more images than these
 
void function()
{
  //do something - load images, create images, split, morphological operations, color conversions.. - nothing very special
}  


int main()
{
  for( i = 0; names[i] != 0; i++ )
  {
    function();
    cvWaitKey(0);
    if (src) cvReleaseImage(&src);
    ...
    //again, releasing more images - all i declared above
  }
}

The problem is, that the program seems not to be releasing the images, because every time I load a new one(cvWaitKey) in main, it consumes more memory. My questions are: why and how do I fix this? I know this isn't a very smart releasing scheme, but I believe it should still work. I tried moving the declarations and releasing in the function(), but it wasn't any better.

Reply | Threaded
Open this post in threaded view
|

Re: cvReleaseImage

Jean-Pierre Landry
The thing is that memory leaks problem are often found in small details
and you only have supplied block-like structure of your program...
It's almost impossible to help you with that level of details... :-(

I seemed to remember some case where somebody was doing something
similar to this:

IplImage *img = cvCreateImage(...);
img = cvLoadImage(...);
cvReleaseImage(&img);

That person did not realized that cvLoadImage allocated an image that
used the previous pointer making the buffer allocated with
'cvCreateImage' impossible to release...  Initially this person thought
that he was releasing all his images but still got memory leaks...  :-)


rohlik10 wrote:

> Hi guys. I've got a problem with releasing my images - apparently I'm doing something wrong, but I can't discover what it is. My program takes more and more memory and doesn't free it, until I close it. So I have to resize images and make them smaller to be able to do something at all, but I'm still really not happy with it :) So here's what my program looks like:
>
> #include ...
>  //some including
> IplImage* src, *hue, *saturation, *value, *red, *green, *blue, *gray;
>  //there are more images than these
> int x; double y; ...
>  //some declarations
>  
> char *names[] = { "0101.jpg", "0102.jpg", "0103.jpg", "0104.jpg", 0 };
>  //again, there are more images than these
>  
> void function()
> {
>   //do something - load images, create images, split, morphological operations, color conversions.. - nothing very special
> }  
>
>
> int main()
> {
>   for( i = 0; names[i] != 0; i++ )
>   {
>     function();
>     cvWaitKey(0);
>     if (src) cvReleaseImage(&src);
>     ...
>     //again, releasing more images - all i declared above
>   }
> }
>
> The problem is, that the program seems not to be releasing the images, because every time I load a new one(cvWaitKey) in main, it consumes more memory. My questions are: why and how do I fix this? I know this isn't a very smart releasing scheme, but I believe it should still work. I tried moving the declarations and releasing in the function(), but it wasn't any better.
>
>
>
> ------------------------------------
>
> Change settings: http://www.yahoogroups.com/mygroups, select
>    Get Emails (get all posts)
>    Daily Digest (one summary email per day)
>    Read on the web (read posts on the web only)Or Unsubscribe by mailing [hidden email]