Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- delegate void D(ref S s);
- interface I
- {
- void M(D d);
- }
- struct S : I
- {
- public void M(D d)
- {
- d(ref this);
- }
- }
- static class Program
- {
- static void Main()
- {
- I i = new S();
- WeakReference w = new WeakReference(i);
- i.M((ref S s_) => {
- Console.WriteLine("Entered M");
- GC.Collect();
- GC.WaitForPendingFinalizers();
- Console.WriteLine("WeakReference IsAlive: " + w.IsAlive);
- Console.WriteLine("WeakReference Target: " + w.Target);
- i = null;
- GC.Collect();
- GC.WaitForPendingFinalizers();
- Console.WriteLine("WeakReference IsAlive: " + w.IsAlive);
- Console.WriteLine("WeakReference Target: " + w.Target);
- // Console.WriteLine(s_);
- Console.WriteLine("Exiting M");
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement