Re: Best practice using large objects in foreach

Tech-Archive recommends: Fix windows errors by optimizing your registry



So by using A and B, nothing is disposed automatically by the GC once
it hits the end of the loop?

A further clarification:
a: the GC does not dispose; it finalises (if required)
b: the GC doesn't care about "the end of the loop"; it runs on its own
thread, and hunts for abandoned objects in its own sweet time. The CLR
doesn't use reference counting etc (e.g. from COM) that would allow it
to destroy things when they go out of scope, as this is prone to orphan
islands of memory (memory leaks). Rather, it periodically scans
*everything* to see what can still be reached by an active (reachable)
object.

Marc

.