表单关闭后内存不GCing [英] Memory not GCing after form closes

查看:84
本文介绍了表单关闭后内存不GCing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一次发帖,希望我能提供足够的信息,这是有道理的。对不起,如果这很详细,但我相信在帮助我之前有人会问我一个无关的问题,所以我想我现在可以解释一下。


我是小Jr.开发人员在一家小公司工作,作为一名老工程师的学徒(编写30多年)。该程序供员工内部使用,作为作为SQL数据库前端运行的故障单跟踪系统。我最近注意到一小部分用户会定期(每周一次)获得内存异常,所以我得到了一个分析工具来调查问题。我在处理它提供的大量信息时遇到了麻烦,不幸的是,这个问题对于我的首席开发人员而言并不是一个足够大的问题,因为他无法摆脱目前的项目。我希望能够在不强迫他停止正在做的事情的情况下处理这个问题。


问题:

常用表格(MDI孩子)查看/编辑故障单不会收集它在合理的时间内关闭时消耗的任何第2代内存。它最终必须收集,否则这个问题会影响到每个人,但是在我做的较短的测试中(10-15分钟)它根本不收集。


剖析器显示表单中最大的残余是datarows,由MDI父级通过System.Windows.Forms.PropertyStore + ObjectEntry []引用。我读过这是因为.net没有收集最后一个MDI孩子。但是,即使我打开3个表单,然后全部关闭它们,其中任何一个都没有释放内存。第二代的内存使用量继续增长。 Gen 0和1收集。


在MDI父级中,存储用于关系的多个表的数据集由此MDI子表单复制,这样我们就不会进行连续调用到他们的SQL服务器。我认为这可能是保持形式存在的参考。我不确定。如果是这种情况,如何在关闭表单时或之后删除此引用?


如果不是这样,我怎样才能找到被引用的内容?


我知道这很多,我感谢你们给予的任何帮助。

解决方案

只是因为表格关闭了没有'' t意味着表单的对象将被收集垃圾。当CLR认为有必要时会发生垃圾收集,但您可以请求使用垃圾收集。

展开 | 选择 | 换行 | 行号


我试过了,它并没有影响内存池。


我知道它在某处保留了内存,来自MDI父级的引用仍然存在之后表单上有dispose()调用它。


我需要一些帮助来理解如何找到引用,和/或如何销毁它。


< blockquote>我真的很喜欢鳗鱼喜欢,基于内存分析器的信息,原因是这些数据集。

当程序启动时,MDI父级从SQL服务器获取一堆表,并且将它们放在数据集中。 MDI Child使用dataset.copy()来获取它们而无需访问SQL服务器。


使用copy()是否创建了对MDI父表单的引用?如果是这样,我该如何打破此引用?


First time posting, hope I can provide enough information that this makes sense. Sorry if this gets verbose, but I am sure someone will ask me an unrelated question before helping me, so I figure I might as well explain it all now.

I am a Jr. developer at a small company working in as sort of an apprentice to an older developer (coding for 30+ years). The program is for internal use by employees as a ticket tracking system running as a front end for a SQL database. I noticed recently that a small group of users will periodically (once a week) get memory exceptions, so I got a profiling tool to look into the problem. I am having trouble working with the wealth of information it is supplying, and unfortunately the problem is not yet a large enough concern to my lead developer for him to pull away from his current project. I am hoping to be able to handle this without forcing him to stop what he is doing.

The Problem:
A commonly used form (MDI child) to view/edit tickets does not collect ANY of the gen 2 memory it is consuming when it is closed within a reasonable amount of time. It eventually must collect, or this issue would be affecting everyone, but in the shorter tests I have done (10-15 minutes) it does not collect at all.

The profiler shows that the largest remnant from the form is datarows, referenced by the MDI parent from through a System.Windows.Forms.PropertyStore+ObjectEntry[]. I''ve read that this is due to .net not collecting the last MDI child. However, even if I open 3 forms, then close them all, none of the memory from ANY of them releases. The memory use in gen 2 just continues to grow. Gen 0 and 1 collect.

In the MDI parent a dataset that stores a number of tables used for relations is copied by this MDI child form so that we aren''t making continuous calls to the SQL server for them. I think this may be what the reference that is keeping the form alive is. I am not sure though. If this is the case, how do I remove this reference when or after closing the form?

If this is not the case, how can I find what is being referenced?

I know that is a lot, I appreciate any help you guys can give.

解决方案

Just because the form closes doesn''t mean that the objects for the form are going to be Garbage Collected. Garbage collection occures when ever the CLR feels it is necessary, but you can request to have a Garbage Collection run using.

Expand|Select|Wrap|Line Numbers


I tried that, and it did not affect the memory pool.

I know that that it is holding onto memory somewhere, a reference from the MDI parent remains even after the form has dispose() called on it.

I need some help understanding how to locate the reference, and/or how to destroy it.


I really feel like, based on the memory profiler''s information, that the cause is these datasets.

The MDI parent gets a bunch of tables from a SQL server when the program starts, and puts them in a dataset. The MDI Child uses dataset.copy() to get them without accessing the SQL server.

Does using copy() create a reference to the MDI parent form? If so, how do I break this reference?


这篇关于表单关闭后内存不GCing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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