C# 使用opencvsharp的内存泄漏
所以我试图用它来创建一个增强现实跟踪器,我遇到了一个内存泄漏的问题 我正在尝试从相机图像(这是我的标记)中识别矩形,我相当确定有问题的代码是正确的C# 使用opencvsharp的内存泄漏,c#,opencvsharp,C#,Opencvsharp,所以我试图用它来创建一个增强现实跟踪器,我遇到了一个内存泄漏的问题 我正在尝试从相机图像(这是我的标记)中识别矩形,我相当确定有问题的代码是正确的 CvSeq<CvPoint> firstcontour = null; List<MarkerRectangle> rectangles = new List<MarkerRectangle>(); CvMemStorage storage = Cv.Create
CvSeq<CvPoint> firstcontour = null;
List<MarkerRectangle> rectangles = new List<MarkerRectangle>();
CvMemStorage storage = Cv.CreateMemStorage(0);
CvMemStorage storagepoly = Cv.CreateMemStorage(0);
IplImage gsImageContour = Cv.CreateImage(Cv.GetSize(thresholdedImage), thresholdedImage.Depth, thresholdedImage.NChannels);
//find contours
Cv.Copy(thresholdedImage, gsImageContour, null);
int contourCount = Cv.FindContours(gsImageContour, storage, out firstcontour, CvContour.SizeOf,
ContourRetrieval.CComp, ContourChain.ApproxSimple, Cv.Point(0, 0));
CvSeq<CvPoint> polycontour = firstcontour.ApproxPoly(CvContour.SizeOf, storagepoly, ApproxPolyMethod.DP, 4, true);
和/或
CvSeq<CvPoint> polycontour = firstcontour.ApproxPoly(CvContour.SizeOf, storagepoly, ApproxPolyMethod.DP, 4, true);
CvSeq polycontour=firstcontour.ApproxPoly(CvContour.SizeOf,storagepoly,ApproxPolyMethod.DP,4,true);
但是,我不确定我可能做错了什么,因为它们没有存储在任何全局变量中,我希望在它们到达方法末尾时释放内存
它可能是bug,在这种情况下,我怀疑我缺乏修复它的技术专业知识,因为除了uni的几门课程外,我还没有使用非托管代码。但是,我尝试在附加信息下实现修复列表,但没有成功,因此我认为这可能不是问题的原因。您如何确定此处存在内存泄漏?此外,一旦变量超出范围,内存将被释放的期望是无效的——假设这些对象是可终结的对象(如果它们持有非托管资源,我会期望它们是可终结的),那么一旦它们不再被引用,而是终结,它们将有资格终结(以及相关的非托管内存释放)在垃圾收集器运行之前不会发生(甚至可能不会立即发生,具体取决于收集的生成)。
CvSeq<CvPoint> polycontour = firstcontour.ApproxPoly(CvContour.SizeOf, storagepoly, ApproxPolyMethod.DP, 4, true);