user-0 提问: 求大神帮忙寻找c++、opencv处理视频的内存泄漏问题，实在实在找不出了

回复:
user: user-0
content: 引用 1 楼 user-1的回复:    int main(int argc, char * argv[]) {     CvCapture* pCapture = cvCreateCameraCapture(0);     IplImage * pFrame;     IplImage *psrc;     IplImage *src = cvCreateImage(cvSize(700,700), IPL_DEPTH_8U,3);     IplImage *gsrc = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U,1);           IplImage *dsw ;     IplImage *dst;     CvMemStorage *storage;     CvSeq *first_contour;           while(1)     {         psrc=cvQueryFrame(pCapture );                    cvResize(psrc,src,1);         cvCvtColor(src,gsrc,CV_BGR2GRAY);           dsw = cvCreateImage(cvGetSize(src), 8, 1);           dst = cvCreateImage(cvGetSize(src), 8, 3);           storage = cvCreateMemStorage(0);           first_contour = NULL;             //turn the src image to a binary image           //cvThreshold(src, dsw, 125, 255, CV_THRESH_BINARY_INV);           cvThreshold(gsrc, dsw, 100, 255, CV_THRESH_BINARY);             cvFindContours(dsw, storage, &first_contour, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);           cvZero(dst);           int cnt = 0;           for(; first_contour != 0; first_contour = first_contour->h_next)           {               cnt++;               CvScalar color = CV_RGB(rand()&255, rand()&255, rand()&255);               cvDrawContours(dst, first_contour, color, color, 0, 2, CV_FILLED, cvPoint(0, 0));               CvRect rect = cvBoundingRect(first_contour,0);             cvRectangle(dst, cvPoint(rect.x, rect.y), cvPoint(rect.x + rect.width, rect.y + rect.height),CV_RGB(255, 0, 0), 1, 8, 0);         }             printf("the num of contours : %d\n", cnt);             cvNamedWindow( "Source", 1 );           cvShowImage( "Source", src );             cvNamedWindow( "dsw", 1 );           cvShowImage( "dsw", dsw );             cvNamedWindow( "Components", 1 );           cvShowImage( "Components", dst );     		cvReleaseMemStorage(&storage); 		 		cvReleaseImage(&dsw);  // 应移至此处 		cvReleaseImage(&dst); // 应移至此处           char c=cvWaitKey(10);         if(c==27)             break;        }       cvDestroyWindow("Source");     cvDestroyWindow("dsw");     cvDestroyWindow("Components");       //~ cvReleaseImage(&pFrame); //cvReleaseCapture会释放，千万别自己处理     cvReleaseImage(&gsrc);     cvReleaseImage(&src);            //cvReleaseMemStorage(&storage);     cvReleaseCapture(&pCapture);       return 0;   }    大神，真的是无比感谢

user: user-1
content: int main(int argc, char * argv[]) {     CvCapture* pCapture = cvCreateCameraCapture(0);     IplImage * pFrame;     IplImage *psrc;     IplImage *src = cvCreateImage(cvSize(700,700), IPL_DEPTH_8U,3);     IplImage *gsrc = cvCreateImage(cvGetSize(src), IPL_DEPTH_8U,1);           IplImage *dsw ;     IplImage *dst;     CvMemStorage *storage;     CvSeq *first_contour;           while(1)     {         psrc=cvQueryFrame(pCapture );                    cvResize(psrc,src,1);         cvCvtColor(src,gsrc,CV_BGR2GRAY);           dsw = cvCreateImage(cvGetSize(src), 8, 1);           dst = cvCreateImage(cvGetSize(src), 8, 3);           storage = cvCreateMemStorage(0);           first_contour = NULL;             //turn the src image to a binary image           //cvThreshold(src, dsw, 125, 255, CV_THRESH_BINARY_INV);           cvThreshold(gsrc, dsw, 100, 255, CV_THRESH_BINARY);             cvFindContours(dsw, storage, &first_contour, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);           cvZero(dst);           int cnt = 0;           for(; first_contour != 0; first_contour = first_contour->h_next)           {               cnt++;               CvScalar color = CV_RGB(rand()&255, rand()&255, rand()&255);               cvDrawContours(dst, first_contour, color, color, 0, 2, CV_FILLED, cvPoint(0, 0));               CvRect rect = cvBoundingRect(first_contour,0);             cvRectangle(dst, cvPoint(rect.x, rect.y), cvPoint(rect.x + rect.width, rect.y + rect.height),CV_RGB(255, 0, 0), 1, 8, 0);         }             printf("the num of contours : %d\n", cnt);             cvNamedWindow( "Source", 1 );           cvShowImage( "Source", src );             cvNamedWindow( "dsw", 1 );           cvShowImage( "dsw", dsw );             cvNamedWindow( "Components", 1 );           cvShowImage( "Components", dst );     		cvReleaseMemStorage(&storage); 		 		cvReleaseImage(&dsw);  // 应移至此处 		cvReleaseImage(&dst); // 应移至此处           char c=cvWaitKey(10);         if(c==27)             break;        }       cvDestroyWindow("Source");     cvDestroyWindow("dsw");     cvDestroyWindow("Components");       //~ cvReleaseImage(&pFrame); //cvReleaseCapture会释放，千万别自己处理     cvReleaseImage(&gsrc);     cvReleaseImage(&src);            //cvReleaseMemStorage(&storage);     cvReleaseCapture(&pCapture);       return 0;   }