Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Pending Finalizer
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { const int numMFOs=10; const int maxIterations =2; public static void Main(string[] args) { //Your code goes here MyFinalizeObject mfo= null; for(int j = 0; j < numMFOs; j++) { mfo = new MyFinalizeObject(); } mfo = null; //put final mfo to null now GC.Collect(); //force garbage collection GC.WaitForPendingFinalizers(); // Worker loop to perform post-finalization code. for(int i = 0; i < maxIterations; i++) { Console.WriteLine("Doing some post-finalize work"); } } } class MyFinalizeObject { // Make this number very large to cause the finalizer to // do more work. private const int maxIterations = 10; ~MyFinalizeObject() { Console.WriteLine("Finalizing a MyFinalizeObject"); // Do some work. for(int i = 0; i < maxIterations; i++) { // This method performs no operation on i, but prevents // the JIT compiler from optimizing away the code inside // the loop. // GC.KeepAlive(i); } } } }
run
|
edit
|
history
|
help
0
Test
Test
test2
dlritytio
sorted array
pyramidnos
1
new
Nan
Delegate & anonymous method