什么是终结队列及控制+ ThreadMethodEntry? [英] What are the Finalizer Queue and Control+ThreadMethodEntry?

查看:288
本文介绍了什么是终结队列及控制+ ThreadMethodEntry?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有出现内存泄漏一个WindowsForms应用程序,所以我用展鹏的蚂蚁内存分析器来看看对象,我怀疑,发现他们只由对象持有已经在终结队列。太好了,究竟什么是终结器队列?你可以点我最好的定义?你可以共享任何传闻的建议?

I have a WindowsForms app that appears to leak memory, so I used Redgate's ANTS Memory Profiler to look at the objects I suspect and find that they are only held by objects already on the Finalizer Queue. Great, exactly what is a the Finalizer Queue? Can you point me to the best definition? Can you share any anecdotal advice?

此外,所有的终结队列根GC对象是 System.Windows.Forms.Control的+ ThreadMethodEntry 名为来电的对象实例。我看到它参与了多线程的UI交互,但我不知道很多不止于此。原谅我的懒惰显然,承认无知,但这些资源都埋下了供应商的组件中。我说要对这些问题的供应商,但我需要一些指导让我很快地交谈。你可以点我ThreadMethodEntry的最有用的定义吗?任何传闻的建议?

Also, all the root GC objects on the Finalizer Queue are instances of System.Windows.Forms.Control+ThreadMethodEntry objects named "caller". I see that it is involved in multi-thread UI interaction, but I do not know much beyond that. Forgive my apparent laziness and admitted ignorance, but these resources are all buried within a vendor's component. I am talking to the vendor about these issues, but I need some direction to get me up to speed on the conversation. Can you point me to the most useful definition of ThreadMethodEntry too? Any anecdotal advice?

另外,我应该甚至担心在终结队列这些对象?

Also, should I even be concerned about these objects on the finalizer queue?

更新::该<一href="http://www.simple-talk.com/dotnet/.net-framework/understanding-garbage-collection-in-.net/">Red门文章,是有益的。

推荐答案

终结队列保存已定义的释放方法的所有对象。回想一下,一个终结是收集非托管资源,如手柄的一种手段。当垃圾收集器收集垃圾,它移动的任何物体终结到终结队列中。在某些时候later--取决于存储器pressure,气相色谱启发式,当垃圾收集决定收集这些对象的moon--的相位,它走下队列并运行终结

The finalizer queue holds all objects that have a finalizer method defined. Recall that a finalizer is a means to collect unmanaged resources like handles. When the garbage collector collects garbage, it moves any objects with a finalizer into the finalizer queue. At some point later-- depending on memory pressure, GC heuristics, and the phase of the moon-- when the garbage collector decides to collect these objects, it walks down the queue and runs the finalizers.

已经在过去曾与内存泄漏,看到了一堆的终结队列供应商的对象可以马虎code,但它并不表示内存泄漏。通常情况下,良好的code就会暴露,将收集托管和非托管资源的Dispose方法,并在这样做,从终结队列中通过 GC.Sup pressFinalize()。因此,如果供应商的目标都实现Dispose方法,和你的code不调用它,可能会导致终结队列一堆的对象。

Having worked with memory leaks in the past, seeing a bunch your vendor's objects in the finalizer queue could be sloppy code, but it does not indicate a memory leak. Typically, good code will expose a Dispose method that will collect both managed and unmanaged resources, and in doing so, remove themselves from the finalizer queue via GC.SuppressFinalize(). So, if the vendor's objects do implement a Dispose method, and your code doesn't call it, that could lead to a bunch of objects in the finalizer queue.

您是否尝试过创建两个点之间的蚂蚁时间的快照,并比较它们之间创建的对象?这可能会帮助您识别被泄露任何管理对象。

Have you tried creating a snapshot in ANTS between two points in time and comparing the objects created between them? That may help you identify any managed objects being leaked.

另外,如果你想看看记忆消失的终结器运行时,试试这个只是为了测试用:

Also, if you want to see if the memory goes away when the finalizers are run, try this just to test with:


System.GC.Collect();
System.GC.WaitForPendingFinalizers(); // this method may block while it runs the finalizers
System.GC.Collect();

我不建议正常运行此code。您可能要运行它,如果你刚刚做大量的工作,创造了大量的垃圾。例如,在我们的应用程序,我们的功能可以创造约350 MB的垃圾的去关闭一个MDI窗口之后浪费。由于这是众所周知的留下大量的垃圾,我们手动强制垃圾收集。

I do not recommend running this code normally. You might want to run it if you've just done a ton of work and created lots of garbage. For example, in our app, one of our functions can create about 350 MB of garbage that goes to waste after closing an MDI window. Since this is known to leave lots of garbage, we manually force garbage collection.

另外请注意,有一个在基地Windows.Forms的code表示将坚持到最后打开模态对话框一个低级别的属性缓存。这可能是内存泄漏源。一个肯定的方式来摆脱这种引用是迫使另一个简单的对话框出现,然后运行上面的GC code。

Also note that there is a low-level property cache in the base Windows.Forms code that will hold on to the last opened modal dialog. This could be a source of a memory leak. One sure way to get rid of this reference is to force another simple dialog to appear, then run the above GC code.

这篇关于什么是终结队列及控制+ ThreadMethodEntry?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆