当你所做的一切错误

当你所做的一切错误

本文介绍了策略跟踪内存泄漏,当你所做的一切错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序,唉,有内存泄漏的地方,但如果我知道它是什么,我会被定罪。

My program, alas, has a memory leak somewhere, but I'll be damned if I know what it is.

它的任务是在一堆阅读的〜2MB的文件,做了一些分析和字符串替换,然后将它们输出各种格式。当然,这意味着大量的字符串,而这样做的内存跟踪显示,我有很多的字符串,而这正是我所期望的。该方案的结构是一系列类(每个在其自己的线程,因为我是一个的白痴的),该行为表示在存储器中的每个文件中的对象上。 (每个对象都有一个使用两端的锁输入队列。虽然这意味着我可以并行运行这个简单的处理,这也意味着我有多个2MB对象坐在内存)。每个对象的结构是由一个模式对象定义

Its job is to read in a bunch of ~2MB files, do some parsing and string replacement, then output them in various formats. Naturally, this means a lot of strings, and so doing memory tracing shows that I have a lot of strings, which is exactly what I'd expect. The structure of the program is a series of classes (each in their own thread, because I'm an idiot) that acts on an object that represents each file in memory. (Each object has an input queue that uses a lock on both ends. While this means I get to run this simple processing in parallel, it also means I have multiple 2MB objects sitting in memory.) Each object's structure is defined by a schema object.

我的加工类引发事件时,他们已经完成了他们的处理和传递对包含我的所有字符串将其添加到下一个处理对象的队列中的大对象。用一个函数调用的更换事件添加到队列不会停止泄漏。其中一个输出格式要求我使用非托管对象。在类中实现的Dispose()不停止泄漏。我已经替换为架构对象的所有引用与索引名。没有骰子。我不知道是什么原因引起的,也不知道去哪里找。记忆痕迹没有帮助,因为我看到的是正在创建一串字符串,我没有看到那里的引用在内存中坚持。

My processing classes raise events when they've done their processing and pass a reference to the large object that holds all my strings to add it to the next processing object's queue. Replacing the event with a function call to add to the queue does not stop the leak. One of the output formats requires me to use an unmanaged object. Implementing Dispose() on the class does not stop the leak. I've replaced all the references to the schema object with an index name. No dice. I got no idea what's causing it, and no idea where to look. The memory trace doesn't help because all I see are a bunch of strings being created, and I don't see where the references are sticking in memory.

我们'重新几乎打算放弃并回滚在这一点上,但我有一种病态的需要知道我究竟是如何搞砸这件事。我知道堆栈溢出不能确切地梳理我的代码,但你可以建议什么样的战略来跟踪该泄漏下来?我可能要做到这一点在我自己的时间,所以任何的办法是可行的。

We're pretty much going to give up and roll back at this point, but I have a pathological need to know exactly how I messed this up. I know Stack Overflow can't exactly comb my code, but what strategies can you suggest for tracking this leak down? I'm probably going to do this in my own time, so any approach is viable.

推荐答案

一种方法我会尝试是系统地减少代码量需要说明问题而不使问题消失。这被非正式地称为分而治之,是一个功能强大的调试技术。一旦你的演示了同样的问题的的例子,这将是您更容易理解。也许内存问题将在此时变得更为清晰。

One technique I would try is to systematically reduce the amount of code you need to demonstrate the problem without making the problem go away. This is informally known as "divide and conquer" and is a powerful debugging technique. Once you have a small example that demonstrates the same problem, it will be much easier for you to understand. Perhaps the memory problem will become clearer at that point.

这篇关于策略跟踪内存泄漏,当你所做的一切错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 14:42