Skip to content

Instantly share code, notes, and snippets.

@heybdj
Forked from anonymous/gist:57f0a6c3b1204d199a44
Last active August 29, 2015 14:23
Show Gist options
  • Save heybdj/8f0dba788ac68853efcb to your computer and use it in GitHub Desktop.
Save heybdj/8f0dba788ac68853efcb 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