Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Hi just to clairfy if I have the following:

using (Object1) {
create Object2
}
// bookmark1

Will Object2 be destroyed at bookmark1 along with Object1? Object2 is of StringReader and Object1 is of MemoryStream.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
131 views
Welcome To Ask or Share your Answers For Others

1 Answer

Neither object will be destroyed at the end of the block.

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.

See IDisposable on MSDN for more.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...