Created
May 3, 2009 23:03
-
-
Save SamSaffron/106190 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Diagnostics; | |
namespace ConsoleApplication11 { | |
class Program { | |
class Foo { | |
int[] nums = new int[10000]; | |
public void Dispose2() { | |
var weakRef = GetWeakRef(); | |
GC.Collect(); | |
GC.WaitForPendingFinalizers(); | |
GC.SuppressFinalize(weakRef.Target); | |
} | |
private WeakReference GetWeakRef() { | |
var weakRef = new WeakReference(this); | |
return weakRef; | |
} | |
~Foo() { | |
Debug.Assert(false); | |
} | |
} | |
static void Main(string[] args) { | |
Stack<Foo> foos = new Stack<Foo>(Enumerable.Range(1,50000).Select(_ => new Foo())); | |
Console.WriteLine("got foo"); | |
while(foos.Count > 0) { | |
var foo = foos.Pop(); | |
foo.Dispose2(); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment