English 中文(简体)
脑膜炎中的记忆泄漏?
原标题:A memory leak in cvCaptureFromCAM?

由此可见,利用传统观念,在初创中创造了记忆。 利用CvCaptureFromCAM造成48个NSAutoreleasePool物体的传闻。 我最初认为我的方案有点.,但当用一个更简单的方案取代时,记忆的泄露仍然存在。

例如:

#include <opencv2/opencv.hpp>
int main()
{
   IplImage *frame = 0;
   CvCapture *capture = cvCaptureFromCAM (-1); //leak occurs on this line  
   //using 0 instead of -1 creates a leak too

   cvNamedWindow ("Output", CV_WINDOW_AUTOSIZE);

   while (1)
   {
      frame = cvQueryFrame (capture);
      cvShowImage ("Output", frame);
   }

   cvDestroyAllWindows ();
   cvReleaseCapture (&capture);

   return 0;
}

I am using Xcode Leaks to find memory leaks and am obviously using the Xcode IDE on Mac OS X 10.6. Does anyone know a solution to the leak? Am I doing something wrong or it a bug in OpenCV or a problem with my computer? I double checked my code and the OpenCV code but couldn t really find a problem. The memory leak is a one time thing - it doesn t keep building. However I am not comfortable with leaving ANY leaks in my program. Does anyone have any suggestions?

最佳回答

遗憾的是,我无法发现CvCaptureFromCAM的泄漏,因此我转向C++接口,并使用了录像带,看来没有泄漏。

问题回答

i 认为问题在于此。

while (1)
{
   frame = cvQueryFrame (capture);
   cvShowImage ("Output", frame);
}

in my idea you have to change this unlimited WHILE to FOR and for have to be fix memory size and after for you have to use

Release();
 or 
EndQuery();

i) 这种方法

 while (1)
 {
  for(int i=0;i<x;++i)
  {
      frame = cvQueryFrame (capture);
      cvShowImage ("Output", frame);
  }
  Release();
  EndQuery();
 }

我找到了<代码>cv:VideoCapture和NSAutoreleasePool的记忆。 这些问题都在<条码>中。

我发现以下三个例子:

  1. An NSAutoreleasePool is allocated.
  2. A method exited early (this code very liberally uses early returns out of functions)
  3. Some of these returns do not clean up after themselves when using an early return

因此,每一次编号为<代码>[[NSAutoreleasePool alloc] init],核对<代码>的其余部分功能。 如果在<代码>return之前就没有按照<代码>[[当地人才外流](或无论何种变更名称在全欧使用)的表述,则添加一个。

还有2份其他来源文件使用NSAutoreleasePool,这些问题可能相似,但我没有使用这些档案和避风港。

一旦我确定这一问题,我的记忆就会消失。 同样,使用开放式CV 2.4.2的Im。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签