opencv函数中的内存泄漏 [英] memory leak in opencv functions
问题描述
我一直注意到我的程序的内存使用有时会毫无意义地不断增加.特别是当我使用cvWaitKey(0)
时,我的程序倾向于在10秒内将内存使用率提高到很大.
I have been noticing that my programs' memory usage keeps increasing pointlessly at times. Specially when i am using cvWaitKey(0)
, my program tends to shoot memory usage in 10 seconds to a huge size.
是否有此修复程序,或者这是OpenCv错误?
Is there a fix for this, or this is an OpenCv bug?
我有一个名为Show_Image
的简单函数,我们已经设置了一个回调函数来获取像素值:
I have a simple function called Show_Image
, to we which have set a callback function to get the pixel values:
void Show_Image(IplImage *img)
{
cvNamedWindow("IMAGE_WINDOW", CV_WINDOW_AUTOSIZE);
cvSetMouseCallback("IMAGE_WINDOW", GETPIXEL , (void*)img);
cvShowImage("IMAGE_WINDOW", img );
cvWaitKey(0);
cvDestroyWindow("IMAGE_WINDOW");
}
推荐答案
似乎没有错误,也没有解决方法.当您调用cvWaitkey()时,该函数将处理所有Windows消息队列.并且因为您有鼠标回调,所以它总是在那里处理某些事情.再加上系统无法显示进程的实际内存使用情况,可能会给您带来虚假的泄漏警报.
It seems there is no error and no workaround for this. When you call cvWaitkey(), the function processes all the windows message queue. And because you have a mouse callback, it always processes something there. This, combined with the weak capability of the system to show the real memory usage for a process, can give you a false leak alarm.
但是,要找到问题的根源,请在您的程序中添加一行代码,如下所示
However, to find the source of the problem, add in your program a line of code, like below
getchar();
等待进程内存增加,然后按任意键退出cvWaitKey()中的消息循环,然后在getchar()函数中等待一分钟.如果那一刻内存没有下降,则可能是泄漏.随时在openCV错误跟踪器中填写票证 https://code.ros.org/trac /opencv/wiki
Wait for the process memory to increase, then press any key to get out of the message loop in cvWaitKey(), and then wait for a minute in the getchar() function. If the memory did not go down in that minute, it may be a leak. Feel free to fill a ticket in the openCV bug tracker https://code.ros.org/trac/opencv/wiki
也可以尝试不同的方法来测量内存的增加: 如何衡量应用程序或流程? 或者 跟踪每个进程的CPU和内存使用情况
Also try different methods to measure the increase in memory: How to measure actual memory usage of an application or process? or Tracking CPU and Memory usage per process
这篇关于opencv函数中的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!