GC收集问题...... [英] GC collection question...

查看:51
本文介绍了GC收集问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个对象 MyEmploye :



Class MyEmploye


{


private string姓名;


私人姓氏姓氏;


}



此实例对象由ArrayList" MyArrayList"的实例引用。 。 MyArrayList的一个实例由ListView的MyListView的每个Item的Tag属性引用。



" Reference"树是:


- ListView


- ListViewItems


- 标签


- MyArrayList


- MyEmploye





我的问题是:



当我调用MyListView.Dispose();时GC是否释放为MyEmploye的所有实例分配的内存?对象?



任何帮助将不胜感激,



谢谢,




Steph。

解决方案




斯蒂芬。写道:

类MyEmploye


请不要使用My-prefix作为类/变量。只需要打电话给他们

它们是什么。

当我调用MyListView.Dispose();时GC是否释放为MyEmploye的所有实例分配的内存?对象?




不,不是*完全*。只要看起来合适,GC就会释放内存。

那不要打扰你,这就是GC的工作方式。


如果处理()清除MyListView.Items然后对MyEmploye

对象的引用消失了,它们应该是垃圾收集的简单。


如果Dispose()*不清楚MyListView.Items,MyEmploye对象
当MyListViewItem对GC变得难以理解时,
对于GC来说是难以理解的,

通常很快就会出现.Dispose()因为你不能做任何事情

用它。


你甚至*想要* Dispose()控制实例的唯一原因是

他们使用了一些非托管资源,很快就可以再次使用

(win32-handles,gfx-resources,...)。


- -

Helge Jensen

mailto:他********** @ slog.dk

sip:他*** *******@slog.dk

- =>塞巴斯蒂安的封面音乐: http://ungdomshus.nu < = -





Steph。写道:

类MyEmploye


请不要使用My-prefix作为类/变量。只需要打电话给他们

它们是什么。

当我调用MyListView.Dispose();时GC是否释放为MyEmploye的所有实例分配的内存?对象?




不,不是*完全*。只要看起来合适,GC就会释放内存。

那不要打扰你,这就是GC的工作方式。


如果处理()清除MyListView.Items然后对MyEmploye

对象的引用消失了,它们应该是垃圾收集的简单。


如果Dispose()*不清楚MyListView.Items,MyEmploye对象
当MyListViewItem对GC变得难以理解时,
对于GC来说是难以理解的,

通常很快就会出现.Dispose()因为你不能做任何事情

用它。


你甚至*想要* Dispose()控制实例的唯一原因是

他们使用了一些非托管资源,很快就可以再次使用

(win32-handles,gfx-resources,...)。


- -

Helge Jensen

mailto:他********** @ slog.dk

sip:他*** *******@slog.dk

- =>塞巴斯蒂安的封面音乐: http://ungdomshus.nu < = -


感谢您的帮助!!


:-)

Steph。


" Helge Jensen" <他********** @ slog.dk>在留言新闻中写道:eo ************* @ TK2MSFTNGP11.phx.gbl ...

Steph。写道:

类MyEmploye


请不要使用My-prefix作为类/变量。只需要打电话给他们

它们是什么。

当我调用MyListView.Dispose();时GC是否释放为MyEmploye的所有实例分配的内存?对象?




不,不是*完全*。只要看起来合适,GC就会释放内存。

那不要打扰你,这就是GC的工作方式。


如果Dispose()清除了MyListView.Items,那么对MyEmploye的引用

对象已经消失,它们应该是垃圾收集的简单元素。


如果Dispose()确实*不*清除MyListView.Items,MyEmploye对象<当MyListViewItem对GC变得清晰时,
对于GC来说是难以理解的,

通常很快就会出现.Dispose()因为你无法做任何事情

with它。


你甚至*想要* Dispose()控件实例的唯一原因是

他们使用了一些非托管资源,这对你来说很不错很快就会再次获得
(win32-handles,gfx-resources,...)。


-

Helge Jensen

mailto:他********** @ slog.dk

sip:他********** @ slog.dk

- =>塞巴斯蒂安的封面音乐: http://ungdomshus.nu < = -




I have an Object " MyEmploye " :



Class MyEmploye

{

private string Name;

private string Surname;

}


Instances of this object are referenced by instances of an ArrayList "MyArrayList" . One instance of MyArrayList is referenced by the "Tag"'' property of each Item of a ListView "MyListView".



"Reference" tree is :

- ListView

- ListViewItems

- Tag

- MyArrayList

- MyEmploye





My question is :



When I call "MyListView.Dispose();" does the GC free the memory allocated for the all the instances of "MyEmploye" objects ?



Any help will be appreciated,



Thanks,



Steph.

解决方案



Steph. wrote:

Class MyEmploye
Please, don''t use My-prefix for your classes/variables. just call them
what they are.
When I call "MyListView.Dispose();" does the GC free the memory
allocated for the all the instances of "MyEmploye" objects ?



No, not *exactly*. The GC will free that memory whenever it sees fit.
That shoudn''t bother you, that''s how a GC works.

If Dispose() clears MyListView.Items then the references to MyEmploye
objects are gone and they should be elegible for garbage-collection.

If Dispose() does *not* clear MyListView.Items, the MyEmploye objects
become elegible for GC when MyListViewItem becomes elegible for GC,
which is usually very soon after .Dispose() since you cannot do anything
with it.

The only reason you would even *want* to Dispose() Control instances are
that they use some unmanaged resources, which would be nice to have
available again soon (win32-handles, gfx-resources, ...).

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-




Steph. wrote:

Class MyEmploye
Please, don''t use My-prefix for your classes/variables. just call them
what they are.
When I call "MyListView.Dispose();" does the GC free the memory
allocated for the all the instances of "MyEmploye" objects ?



No, not *exactly*. The GC will free that memory whenever it sees fit.
That shoudn''t bother you, that''s how a GC works.

If Dispose() clears MyListView.Items then the references to MyEmploye
objects are gone and they should be elegible for garbage-collection.

If Dispose() does *not* clear MyListView.Items, the MyEmploye objects
become elegible for GC when MyListViewItem becomes elegible for GC,
which is usually very soon after .Dispose() since you cannot do anything
with it.

The only reason you would even *want* to Dispose() Control instances are
that they use some unmanaged resources, which would be nice to have
available again soon (win32-handles, gfx-resources, ...).

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-


Thanks for the Help !!

:-)

Steph.

"Helge Jensen" <he**********@slog.dk> wrote in message news:eo*************@TK2MSFTNGP11.phx.gbl...
Steph. wrote:

Class MyEmploye
Please, don''t use My-prefix for your classes/variables. just call them
what they are.
When I call "MyListView.Dispose();" does the GC free the memory
allocated for the all the instances of "MyEmploye" objects ?



No, not *exactly*. The GC will free that memory whenever it sees fit.
That shoudn''t bother you, that''s how a GC works.

If Dispose() clears MyListView.Items then the references to MyEmploye
objects are gone and they should be elegible for garbage-collection.

If Dispose() does *not* clear MyListView.Items, the MyEmploye objects
become elegible for GC when MyListViewItem becomes elegible for GC,
which is usually very soon after .Dispose() since you cannot do anything
with it.

The only reason you would even *want* to Dispose() Control instances are
that they use some unmanaged resources, which would be nice to have
available again soon (win32-handles, gfx-resources, ...).

--
Helge Jensen
mailto:he**********@slog.dk
sip:he**********@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-


这篇关于GC收集问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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