Skip to content

Instantly share code, notes, and snippets.

Created June 6, 2015 11:34
Show Gist options
  • Save anonymous/57f0a6c3b1204d199a44 to your computer and use it in GitHub Desktop.
Save anonymous/57f0a6c3b1204d199a44 to your computer and use it in GitHub Desktop.
public void ForcedFullGarbageCollection() {
var size = GC.GetTotalMemory(false);
for (var i = 0; i < 100; ++i) {
GC.Collect();
GC.WaitForFullGCComplete();
GC.WaitForPendingFinalizers();
var newSize = GC.GetTotalMemory(false);
var delta = (size - newSize) / (double)size;
if (delta < 0.01)
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment