Re: How does "new" work in a loop?

Tech-Archive recommends: Speed Up your PC by fixing your registry



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
.



Relevant Pages

  • Re: Black-drop - is it real?
    ... Still amazed at what I can see with the scope, ... no idea why) is the one showing the trees. ... I believ that I can see it in the picture I mentioned in the original post. ...
    (sci.astro.amateur)
  • Re: Whats the differences between REGISTER and AUTO?
    ... which can be a smaller scope than the entire function. ... int fred (void) ... <snip good stuff> ...
    (comp.lang.c)
  • Re: Scope
    ... what you were asking about isn't scope. ... FWIW the C standard uses 'duration'. ... released resources and broken invariants. ...
    (comp.lang.fortran)
  • Re: Strange interaction of "my"-variables with initialization
    ... You can use it because it is in the same scope. ... conditional form of for still localizes $_, ... The "foreach" loop iterates over a normal list value and sets the ...
    (perl.beginners)
  • Re: How does the break statement work?
    ... within the current scope. ... a misleading assertion. ... all looping constructs may use any ...
    (comp.lang.javascript)