OpenCV 3.0 - Memory Leaks in MFC Project

asked 2015-07-19 10:58:50 -0600

fordicus gravatar image

The Example Source Code is,

using namespace cv;
VideoCapture cap(0);
cvNamedWindow("wnd_00");
Mat preview;
while (1){
    if (waitKey(5) > 0) break;
    cap >> preview;
    imshow("wnd_00", preview);
}   destroyAllWindows();

This is my first time to get through this type of problem using OpenCV. And now I have referred to many cases just like this from on-line postings, which has persisted from older versions. It is regarded to happen when using OpenCV in Windows MFC project, and when it is being run in Debug Mode.

Most important part is that, people assume the memory leak being indicated here is the "false alarm" because the function call "_CrtDumpMemoryLeaks()" in Visual Studio for detecting the memory leak is just earlier than the Exit Operation of the OpenCV's dll.

Though there are couple of options to suppress this "false alarm", those are actually the temporary solutions or it might take too much time to solve it actually. Thus I shall just choose to neglect it "believing it won't be the problem in Release version of the project, as it is the false alarm in Debug session".

Then, how could I really be convinced that there will be no memory leak in Release Version if I didn't do any mistake in my code? Have any advice or suggestion to deal with it?


The Output Console Message from Visual Studio Debugging Session

VIDEOINPUT LIBRARY - 0.1995 - TFW07

SETUP: Setting up device 0 SETUP: Vimicro USB Camera (Altair) SETUP: Couldn't find preview pin using SmartTee SETUP: Default Format is set to 640x480 SETUP: trying specified format RGB24 @ 640x480 SETUP: trying format RGB24 @ 640x480 SETUP: trying format RGB32 @ 640x480 SETUP: trying format RGB555 @ 640x480 SETUP: trying format RGB565 @ 640x480 SETUP: trying format YUY2 @ 640x480 SETUP: Capture callback set SETUP: Device is setup and ready to capture.

SETUP: Disconnecting device 0 SETUP: freeing Grabber Callback SETUP: freeing Grabber SETUP: freeing Control SETUP: freeing Media Type SETUP: removing filter NullRenderer... SETUP: filter removed NullRenderer SETUP: removing filter Sample Grabber... SETUP: filter removed Sample Grabber SETUP: removing filter AVI Decompressor... SETUP: filter removed AVI Decompressor SETUP: removing filter Smart Tee... SETUP: filter removed Smart Tee SETUP: removing filter Vimicro USB Camera (Altair)... SETUP: filter removed Vimicro USB Camera (Altair) SETUP: freeing Capture Graph SETUP: freeing Main Graph SETUP: Device 0 disconnected and freed

Detected memory leaks! Dumping objects -> {835} normal block at 0x005FCD18, 56 bytes long. Data: < > 90 A3 FD 11 00 00 00 00 00 00 00 00 CD CD CD CD {834} normal block at 0x005FC950, 908 bytes long. Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 80 02 00 00 {806} normal block at 0x0786C370, 44 bytes long.

....ellipsis

Object dump complete.

edit retag flag offensive close merge delete

Comments

Hi, I guess the while loop you use destroyAllWindows to destory window, maybe memory leak happens here.

wuling gravatar imagewuling ( 2015-07-19 22:06:46 -0600 )edit