我有一个小的内存泄漏,我把它缩小到以下功能:
// 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;
}
在我注释掉对此函数的调用后,内存泄漏消失了。另外,我在我的main函数中调用cvReleaseMat(src_image),因此这不是问题的根源。谁知道问题是什么?我一直在盯着这几个小时....非常感谢!