Folks, lets say I have a loop as follows:
foreach (Object myObject in myObjectCollection)
Object veryLargeObject = GetVeryLargeObject()
// do some stuff
// no longer need veryLargeObject
GetVeryLargeObject returns an object that takes up a lot of memory. Over time, this loop causes an OutOfMemoryException. Is there a way to explicitly garbage collect veryLargeObject? I tried doing the following, but it doesn't seem to work:
veryLargeObject = null;
is this because i'm iterating the in the scope of a method? Are all the created veryLargeObject objects candidates for garbage collection AFTER I exit the method? What's the best practice here?