views:

58

answers:

1

Hello OpenCV'ers,

I am using the OpenCV function: cvExtractSURF but I am finding a major memory leak. Has anyone successfully implemented this call? My code is as follows:

IplImage *cvImage = [self CreateIplImageFromUIImage:image grayscale:YES];

CvMemStorage* storage = cvCreateMemStorage(0);

CvSeq *objectKeypoints = 0;
//CvSeq *objectDescriptors = 0;

CvSURFParams params = cvSURFParams(self.hessianThreshold, 0);
double tt = (double)cvGetTickCount();

//Extract the features
cvExtractSURF( cvImage, 0, &objectKeypoints, NULL, storage, params, 0);

tt = (double)cvGetTickCount() - tt;
//NSLog(@"%d features found in %gms seconds\n", objectKeypoints->total, tt/(cvGetTickFrequency()*1000.));

cvReleaseImage(&cvImage);
cvReleaseMemStorage(&storage);

Any ideas where this could be leaking? When I comment out the line:

cvExtractSURF( cvImage, 0, &objectKeypoints, NULL, storage, params, 0);

no leak occurs.

Many many thanks, Brett

+2  A: 

The function cvExtractSURF creates a list of objects of type CvSURFPoint and puts a pointer to it in objectKeypoints. You have to free that up.

Add a call...

cvRelease((void **)&objectKeypoints);
Jive Dadson
Hey, I wanna green check mark. :-)
Jive Dadson
Green check mark earned :) I actually had to use cvRelease((void **) Not too sure why this works.
Brett
Right. cvRelease works via ad hoc polymorphism, which is why you need the cast. I was too lazy to test the code, or I would have caught that. I've updated the answer to include the cast. Oh. And thanks for the check mark.
Jive Dadson