Re: How does "new" work in a loop?
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Thu, 6 Jul 2006 22:42:14 +0100
Matt <matttelles@xxxxxxxxxxx> wrote:
<snip>
Unlikely that you are creating a memory leak. C# uses garbage
collection. When the object goes out of scope (in your case, the }
marked // for int i) the object is destroyed. The next time through
the loop, a new one is created.
The object is *not* destroyed when it reaches the end of the scope.
..NET does not have deterministic garbage collection. Instead, the
object's memory will be released *at some point* after it is last used.
In fact, this could be before the end of the scope - the GC could kick
in before progBar.Value++ and free both fs and inputBuffer.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: How does "new" work in a loop?
- From: Göran Andersson
- Re: How does "new" work in a loop?
- References:
- How does "new" work in a loop?
- From: Tony Sinclair
- Re: How does "new" work in a loop?
- From: Matt
- How does "new" work in a loop?
- Prev by Date: Re: How does "new" work in a loop?
- Next by Date: Re: How does "new" work in a loop?
- Previous by thread: Re: How does "new" work in a loop?
- Next by thread: Re: How does "new" work in a loop?
- Index(es):
Relevant Pages
|