简体   繁体   English

无法使用ANTS RedGate Memory Profiler解决内存泄漏问题

[英]Unable to resolve memory leaks with ANTS RedGate Memory Profiler

we are developing a WPF application using Prism 4 and are experiencing serious memory leaks because of resources not being released. 我们正在使用Prism 4开发一个WPF应用程序,并且由于资源未被释放而正在经历严重的内存泄漏。 We are using ANTS Memory Profiler to detect which classes are preventing the garbage collector from freeing the memory, but we are very new to this tool, so our understanding of its output is limited. 我们正在使用ANTS Memory Profiler来检测哪些类阻止垃圾收集器释放内存,但我们对这个工具很新,因此我们对其输出的理解是有限的。

Our test case consists in opening a window that lets you choose a plugin from a list. 我们的测试用例包括打开一个窗口,让您从列表中选择一个插件。 The window hosts a Wizard control that contains a header, a set of buttons and a main area that displays the active WizardPage (that is a UserControl). 该窗口包含一个向导控件,该控件包含一个标题,一组按钮和一个显示活动WizardPage(即UserControl)的主区域。 By choosing a plugin and clicking the Next button, more WizardPage controls are registered in the Wizard Region and added to the Wizard.Pages collection using a RegionAdapter. 通过选择插件并单击“下一步”按钮,可以在向导区域中注册更多的WizardPage控件,并使用RegionAdapter将其添加到Wizard.Pages集合中。 The user can then move through the pages by clicking the Next/Previous buttons. 然后,用户可以通过单击“下一个/上一个”按钮来浏览页面。 If we open the Wizard window and just click the Cancel button, the Wizard control finalizer is called as expected. 如果我们打开向导窗口并单击“取消”按钮,则会按预期调用向导控件终结器。 However, if we open the Wizard window and expand the plugins ComboBox before clicking the Cancel button, then the Wizard control finalizer is never called. 但是,如果我们打开向导窗口并在单击“取消”按钮之前展开插件ComboBox,则永远不会调用向导控件终结器。 Here is a screenshot of the Instance Categorizer for Wizard in ANTS Memory Profiler: 以下是ANTS Memory Profiler中向导实例分类程序的屏幕截图:

实例分类程序

We tried almost everything with no success, could someone help us to understand what's going on here? 我们尝试了几乎所有事情都没有成功,有人可以帮助我们了解这里发生了什么吗?

Thank you in advance. 先感谢您。

If you're just starting out with ANTS Memory Profiler , you might find it most useful to start by looking at the class list instead of the instance categorizer . 如果您刚刚开始使用ANTS Memory Profiler ,您可能会发现从查看类列表而不是实例分类程序开始最有用。

A good approach would probably be to start by taking a baseline snapshot before clicking the Next button in your application. 一种好的方法可能是在单击应用程序中的“下一步”按钮之前先拍摄基线快照。 Then open the Wizard Window and expand the plugins combobox, then click Cancel. 然后打开向导窗口并展开插件组合框,然后单击取消。 At that point, take another memory snapshot in ANTS, and compare the two. 此时,在ANTS中拍摄另一个内存快照,并比较两者。 If you go into the class list , you'll probably see an instance of the WizardPage class which exists in memory now which didn't exist previously and which should have been removed. 如果你进入类列表 ,你可能会看到一个WizardPage类的实例现在存在于内存中,该实例以前不存在,应该被删除。 Select that and then in ANTS go to the instance list . 选择它,然后在ANTS中转到实例列表

Select the instance of WizardPage and click to see the instance retention graph , which shows the chains of references back to the GC roots which are holding that specific instance in memory. 选择WizardPage的实例,然后单击以查看实例保留图 ,该显示返回GC根的引用链,这些引用链将特定实例保存在内存中。

By looking back up those chains of references, you should be able to identify which link exists which should be broken in order to free the object from memory. 通过查看这些引用链,您应该能够识别哪个链接应该被破坏以便从内存中释放对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM