Memory leak with morphological operators
Hi everyone,
It might be a stupid question but..why Visual Studio (2010) says there's a memory leak here? I'm using OpenCV 2.4.1 with TBB support.
int main()
{
Mat mask(480, 640, CV_8U, Scalar(255));
cv::erode(mask, mask, cv::Mat());
// Turn on memory leaks detection.
_CrtSetDbgFlag((_CRTDBG_LEAK_CHECK_DF) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
return 0;
}
Regards,
Giuliano
Do you still have this leak if comment erode call?
Commenting the erode, the leak disappears. Same stuff using "dilate".
Thank you for response. Could you try to run erode in cycle and see in task manager is memory leaks or not. Now I'm on linux, in system monitor no memory leaks; checked with some tools, they aren't reported about leaks. May be it's windows specific?
If I run erode in a loop, the allocated memory does not increase. There's still only one memory leak. Checking where that memory is allocated, I can see some references to TBB code (starting from morph.cpp:1183).
I suppose, that in this example with erode threading isn't used, because tbb implementation doesn't support inplace calculation (source is a destination at the same time). Please, try to add cv::Ptr<tbb::task_scheduler_init>; tbb_init = new tbb::task_scheduler_init(); before erode call. Is now memory leak?
It seems the line of code fixes the issue! What's the explanation? I've never used TBB before.
Many thanks for testing, I've posted the answer.