由此可见,利用传统观念,在初创中创造了记忆。 利用CvCaptureFromCAM造成48个NSAutoreleasePool物体的传闻。 我最初认为我的方案有点.,但当用一个更简单的方案取代时,记忆的泄露仍然存在。
例如:
#include <opencv2/opencv.hpp>
int main()
{
IplImage *frame = 0;
CvCapture *capture = cvCaptureFromCAM (-1); //leak occurs on this line
//using 0 instead of -1 creates a leak too
cvNamedWindow ("Output", CV_WINDOW_AUTOSIZE);
while (1)
{
frame = cvQueryFrame (capture);
cvShowImage ("Output", frame);
}
cvDestroyAllWindows ();
cvReleaseCapture (&capture);
return 0;
}
I am using Xcode Leaks to find memory leaks and am obviously using the Xcode IDE on Mac OS X 10.6. Does anyone know a solution to the leak? Am I doing something wrong or it a bug in OpenCV or a problem with my computer? I double checked my code and the OpenCV code but couldn t really find a problem. The memory leak is a one time thing - it doesn t keep building. However I am not comfortable with leaving ANY leaks in my program. Does anyone have any suggestions?