[英]What is causing my memory leak with OpenCV
我正在尝试在应用程序中实现OpenCV,但是每次调用函数时都会发生内存泄漏。 我想这与我在Visual Studio中使用该库的方式有关,但是我用一个空白项目对其进行了测试,并且在相同的设置下它似乎可以正常工作。
我尝试实现的代码为:
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize Microsoft Foundation Classes, and print an error if failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// Application starts here...
// Time the application's execution time.
TIMER start;
// CODE TO GO HERE!
TIMER end;
TIMER elapsed;
elapsed = end - start;
__int64 ticks_per_second = start.get_frequency();
// Display the resulting time...
double elapsed_seconds = (double)elapsed.get_time() / (double)ticks_per_second;
cout << "Elapsed time (seconds): " << elapsed_seconds;
cout << endl;
cout << "Press a key to continue" << endl;
char c;
cin >> c;
}
return nRetCode;
}
如果我实现一些简单的事情:
cv::Mat aVar;
在我放置“ CODE TO HERE!”的地方 Visual Studio说程序终止后会发生内存泄漏。 任何想法可能是什么问题?
我在调试版本中注意到,当您另外使用fopen和fread时,MFC和OpenCV的组合也会导致奇怪的行为。 fread可能返回错误9(存储控制块地址无效)。
同样,延迟加载OpenCV dll可能会解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.