Ask Your Question

memory leak in loop

asked 2012-11-17 08:18:05 -0500

KFP gravatar image

updated 2012-11-17 10:28:43 -0500

sammy gravatar image

I'm using a simple for loop to do X itterations of the same filter:

void filterwrapper(IplImage *src, IplImage **dst, int filter_sel,
      int param1, int param2, int iterations) 
    int i;
    *dst = cvCloneImage(src);
    for (i = 0; i < iterations; i++)
        cvSmooth( *dst, *dst, CV_MEDIAN, param1, 0);

I'm aware i somehow have to release the memory using cvReleasimg(), but doing so inside the loop causes my program to crash. I've tried using a temporary image (IplImage *tmp) as a placeholder and releasing this each loop, but i still get an memory allocation error when running the program.

edit retag flag offensive close merge delete


Your code is correct elsewhere there is an error.

Mostafa Sataki gravatar imageMostafa Sataki ( 2012-11-17 11:24:23 -0500 )edit

thx for your repply. switcing from cvCloneImage to cvCopy cleared the issue

KFP gravatar imageKFP ( 2012-11-18 11:51:05 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2012-11-19 01:56:58 -0500

SR gravatar image

From the doc:

Median and bilateral filters work with 1- or 3-channel 8-bit images and can not process images in-place.

You must use different matrices for input and output, e.g. cvSmooth(*src, *dst, CV_MEDIAN, param1, 0);

edit flag offensive delete link more


In OpenCV 2.4 In-place operation is supported for both

Mostafa Sataki gravatar imageMostafa Sataki ( 2012-11-19 02:04:25 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2012-11-17 08:18:05 -0500

Seen: 720 times

Last updated: Nov 19 '12