使用和垃圾收集 [英] Using and Garbage Collection
问题描述
喜只是clairfy如果我有以下几点:
Hi just to clairfy if I have the following:
using (Object1) {
create Object2
}
// bookmark1
将被Object2的在bookmark1与Object1一起被毁坏?
Object2的是StringReader和Object1是的MemoryStream的。
Will Object2 be destroyed at bookmark1 along with Object1? Object2 is of StringReader and Object1 is of MemoryStream.
推荐答案
无论对象将摧毁在块的末尾。
Neither object will be destroyed at the end of the block.
Object1将处置,不同的概念;什么都不会发生Object2的。
Object1 will be Disposed, a different concept; nothing will happen to Object2.
这两个对象将被收集,并可能被最终确定,晚些时候。垃圾收集是不确定性 - 你不能依赖何时会发生这
Both objects will be collected, and may be finalised, sometime later. Garbage collection is non-deterministic - you can't rely on when it will occur.
请参阅的 IDisposable的 MSDN上的更多。
See IDisposable on MSDN for more.
这篇关于使用和垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!