Created
December 2, 2014 12:54
-
-
Save rossdargan/fd231df4ae91e0a85245 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
public WeakReference Reference; | |
public override void ViewDidLoad() | |
{ | |
base.ViewDidLoad(); | |
float y = 30; | |
View.BackgroundColor = UIColor.White; | |
// The image we will work with; we derive our own so we can see | |
// it get destroyed. | |
var imageView = new MyImageView(new RectangleF(0, View.Bounds.Height / 2, View.Bounds.Width, View.Bounds.Height / 2)); | |
Add(imageView); | |
Reference = new WeakReference(imageView); | |
// Create the button to remove our image | |
AddButton(ref y, "Remove Image from Screen", | |
(sender, e) => { | |
Console.WriteLine ("Removing image from UI"); | |
imageView.RemoveFromSuperview(); | |
imageView.Dispose(); | |
imageView = null; | |
}); | |
AddButton(ref y, "Output reference", (sender, args) => | |
{ | |
Console.WriteLine(Reference.IsAlive); | |
}); | |
// TODO: Step 1 - Force GC | |
AddButton(ref y, "Force GC Now!", | |
(sender, e) => { | |
// This forces a Garbage Collection | |
Console.WriteLine ("Forcing GC!"); | |
GC.Collect(); | |
GC.WaitForPendingFinalizers(); | |
GC.Collect(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment