Visual Studio 2015 + MFC Office Style + OpenCV 3.1 = Memory Leaks
Hi,
i have problems using OpenCV 3.1 with Visual Studio 2015 (Prof.) and MFC.
First, i build the libraries dynamic:
I use CMake 3.4.1 and select the option "BUILD_SHARED_LIBS". The option "BUILD_WITH_STATIC_CRT" is not selected to build dynamically linked DLLs. At the test program (Simple MFC Office Style, no big extras), i use the opencv core, imgcodecs and imgproc to load a png file and run the canny filter over it. By closing the program, i got many memory leaks. There are the typical "MFC memory leaks" (but the solution to link MFC in OpenCV does not help at this point - the leaks still exists) and there are some leaks with a really high allocation number (the number between the curly brackets) and they seam to be inside of the dll.
Second, i build the libraries static:
For this example, i use the option "BUILD_WITH_STATIC_CRT" and "BUILD_SHARED_LIBS" is deselected. The result is, that most of the MFC typical leaks are gone (2 leaks exists) but the other leaks (with the high allocation number) are still there.
My test code in the 'OnInitialUpdate' method looks like (the loaded image is not displayed):
cv::Mat test;
test = cv::imread("image.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat canny;
cv::Canny(test, canny, 50, 100);
So, now my question: Did i make some mistakes in using or building OpenCV? With the old version (2.4.11) and VS 2012, my way of building works good (with the addition of linking MFC in OpenCV).
Regards, Torben
afaik, when using BUILD_SHARED_LIBS, you have to choose multi-threaded dynamic c-runtime, too.
if you choose BUILD_WITH_STATIC_CRT (because of MFC [baaa]) , you will need to build static opencv libs, and make sure, they use the same (static) c-runtime than your prog later.
Hi.
I think the problem is well described in
http://stackoverflow.com/questions/32...
so it is not as such a memory leak. But it makes it practically impossible for us to use OpenCV 3.1 as any memory leak we made have of our own will drown in all those reported (I have about 88 reports for just starting and stoppping the applicartion - some reported in OpenCV itself, some in the Intel TBB). I identified 2-3 of them in OpenCV and found those just to be static heap allocations of memory/objects).
Unfortunately, as seen from https://github.com/Itseez/opencv/issu... the problem will not be fixed.
So we are for now sticking to an older version 2.4.6.1 of OpenCV.
Regards, also Torben.
PS: We are not using MFC.