Closed fpiette closed 5 years ago
Preliminary conclusion
Example: cv_GoodFeaturesToTrack Code modification:
While True do
begin
ipar1 := 100;
img1 := cvLoadImage(ImgFilename, CV_LOAD_IMAGE_UNCHANGED);
img2 := cvCreateImage(cvGetSize(img1), IPL_DEPTH_8U, 1);
cvCvtColor(img1, img2, CV_RGB2GRAY);
eig := cvCreateImage(cvGetSize(img2), 32, 1);
temp := cvCreateImage(cvGetSize(img2), 32, 1);
points[0] := @pointsRow1[0];
count := 250;
cvGoodFeaturesToTrack(img2, eig, temp, @points[0][0], @ipar1, 0.05, 10, nil, 5, 0, 0.09);
cvFindCornerSubPix(img2, @points[0][0], count, cvSize(5, 5), cvSize(-1, -1), cvTermCriteria(CV_TERMCRIT_ITER or CV_TERMCRIT_EPS, 20, 0.03));
for j := 0 to ipar1 - 1 do
begin
cvCircle(img1, cvPointFrom32f(points[0][j]), 3, CV_RGB(0, 255, 255), -1, 8, 0);
cvCircle(img1, cvPointFrom32f(points[0][j]), 8, CV_RGB(255, 0, 0), -1, 8, 0);
end;
cvNamedWindow('bb', 1);
cvShowImage('bb', img1);
cvWaitKey(1);
cvReleaseImage(img1);
cvReleaseImage(img2);
cvReleaseImage(eig);
cvReleaseImage(temp);
cvDestroyAllWindows;
end;
Result:
Conclusion: A memory leak occurs outside of opencv.
@Laex I was talking about a HANDLE leak, not a memory leak.
I see that every example program suffer from a resource leak.
I see this leak using madExcept which report a thread handle leak. See attached madExcept report created when running example cv_GoodFeaturesToTrack.dproj :
In that sample, the line (62) allocating the leaked thread handle is calling cvCvtColor. I guess the function create a thread to do the conversion.
I suspect that something is missing in the example program to finalize OpenCV and free all resources.
btw: I'm using Delphi 10.3.1.
François Piette Embarcadero MVP