Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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