How can I purposely overflow my memory, to force garbage collection?
Can someone propose algorithm like this:
while ( garbage collector starts ) {
overflow my memory with something easily disposable
}
Edit:
To everyone that purposed GC.Collect method. I’ve always tought, that GC can not be forced to occur programmaticaly. Guess, I was wrong. Thanks for the answers.
Better yet, how ’bout using
GC.Collect? No need to synthesize a condition when there’s an explicit feature available…Also, note the
GC.WaitForPendingFinalizersmethod that Adam Butler (comment above), ChristopheD (answer below), and Michael Petrotta (comment below) pointed out, which takes the next step. Scary quote from the documentation on that method, though: “The thread on which finalizers are run is unspecified, so there is no guarantee that this method will terminate.” shudder