1

我有一个小的内存泄漏,我已将其缩小到以下功能:

 // Input image clusterMat 5-Means clustering, output number of clusters
 public static float contourDetection(CvMat src_image, Hashtable<Integer, Double> table, double gray_value) {
     CvMemStorage storage = cvCreateMemStorage(0);
     CvSeq contours = new CvSeq();
     CvSeq ptr = new CvSeq();
     int sizeofCvContour = Loader.sizeof(CvContour.class);
     float total_num_clusters = 0.0f;

     // Find contours
     cvFindContours( src_image, storage, contours, sizeofCvContour, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);

     for (ptr = contours; ptr != null; ptr = ptr.h_next()) { 
         Integer contour_size = 0;
         if (ptr.total() > 0) {
             contour_size = (int)cvContourArea(ptr, CV_WHOLE_SEQ, 0);
         }
         table.put(contour_size, gray_value);
         total_num_clusters += 1.0f;
     }

     // Release storage
     storage.release();
     contours.deallocate();
     ptr.deallocate();

     return total_num_clusters;
 }

在我注释掉对该函数的调用后,内存泄漏就消失了。另外,我在我的主函数中调用 cvReleaseMat(src_image),所以这不是问题的根源。有人看到问题是什么吗?我已经盯着这个看了几个小时了......非常感谢!

4

0 回答 0