为什么我的窗户得到垃圾回收? [英] Why aren't my windows getting garbage collected?

查看:172
本文介绍了为什么我的窗户得到垃圾回收?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标准的CRUD应用程序,具有相当大数据量的工作。不同的窗口访问使用LINQ到SQL不同的表,每个窗口基本上是有必然,我展示的对象细胞的网格。

I have a standard CRUD application that works with a fairly large amount of data. Different windows access different tables using Linq-To-SQL, and each window essentially has a grid with cells bound to the objects I'm displaying.

下面是一个非常标准的使用发生了什么事的情况下:

Here's a pretty standard use case of what's happening:


  1. 开启窗口A

  2. 关闭窗口A - 窗口A现在仍在内存中,但不再可见

  3. 开启窗口b中

  4. 关闭窗口。b - 视窗A和b现在都在内存中,也不是可见的。

  5. 开启窗口ç

  6. 当数据为窗口ç检索,window的资源将被释放。

  1. Open Window A
  2. Close Window A - Window A is now still in memory but no longer visible.
  3. Open Window B
  4. Close Window B - Windows A and B are now both in memory and neither are visible.
  5. Open Window C
  6. As data is retrieved for Window C, resources for Window A are released.

因此,在任何给定的时间,我保存在内存中2-3窗口时,所有我真的应该有一个。我甚至已经添加处理代码来为这些窗户将所有我能想到的空引用的闭幕活动。

So at any given time I have 2-3 windows held in memory, when all I should really have is one. I have even added disposal code to the closing event for these windows which sets all of the references I can think of to null.

我试着用蚂蚁内存分析器,以及我注意到,每个窗口被设置作为GC根。有没有一种方法来禁用此行为或以某种方式强制GC从这些窗口?

I tried using the ANTS memory profiler, and I'm noticing that each window is set as a GC root. Is there a way to disable this behavior or somehow force the GC to collect from these windows?

谢谢!

PS:我已经检查此链接,并没有解决问题。

PS: I have checked this link and it didn't resolve the issue.

编辑:的问题是,用户越来越System.OutOfMemoryExceptions

The problem is that the users are getting System.OutOfMemoryExceptions.

推荐答案

我能够用两个更新修复这个问题。首先,我是用我的子窗口Telerik控制。该Telerik控制必须跟踪根视觉的,所以,如果他们只是在子窗口实例然后在每个实例化,他们认为子窗口是根视觉和分配一个静态引用。通过实例化我的应用程序主窗口上Telerik的控制,该窗口被设置为根静态参考视觉。

I was able to fix this with two updates. First, I was using Telerik controls on my child windows. The Telerik controls have to keep track of the root visual, so if they're instantiated only on child windows then on each instantiation they assume that the child window is the root visual and assign a static reference to it. By instantiating a telerik control on my main application window, that window was set as the root visual in the static reference.

我所做的第二次更新是为了分配每个子窗口的业主作为我的主要应用程序窗口。这样做的,分析后,我发现子窗口已不再被设置为GC根。

The second update I made was to assign each child window's owner as my main application window. After doing this and profiling I found that child windows were no longer being set as GC roots.

现在我的孩子得到的窗户垃圾自动收集他们关闭之后,一旦新的内存要求为另一扇窗。

Now my child windows get garbage collected automatically after they're closed, as soon as new memory is requested for another window.

这篇关于为什么我的窗户得到垃圾回收?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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