summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Xamarin.Forms.Platform.Android/VisualElementPackager.cs7
-rw-r--r--Xamarin.Forms.Platform.Android/VisualElementTracker.cs24
-rw-r--r--Xamarin.Forms.Platform.WP8/VisualElementTracker.cs44
-rw-r--r--Xamarin.Forms.Platform.WinRT/VisualElementPackager.cs6
4 files changed, 59 insertions, 22 deletions
diff --git a/Xamarin.Forms.Platform.Android/VisualElementPackager.cs b/Xamarin.Forms.Platform.Android/VisualElementPackager.cs
index e6db1c6..891d438 100644
--- a/Xamarin.Forms.Platform.Android/VisualElementPackager.cs
+++ b/Xamarin.Forms.Platform.Android/VisualElementPackager.cs
@@ -33,8 +33,15 @@ namespace Xamarin.Forms.Platform.Android
public void Dispose()
{
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
if (_disposed)
return;
+
_disposed = true;
if (_renderer != null)
diff --git a/Xamarin.Forms.Platform.Android/VisualElementTracker.cs b/Xamarin.Forms.Platform.Android/VisualElementTracker.cs
index 2b9815d..7ade459 100644
--- a/Xamarin.Forms.Platform.Android/VisualElementTracker.cs
+++ b/Xamarin.Forms.Platform.Android/VisualElementTracker.cs
@@ -45,18 +45,28 @@ namespace Xamarin.Forms.Platform.Android
public void Dispose()
{
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
if (_disposed)
return;
- _disposed = true;
- SetElement(_element, null);
+ _disposed = true;
- if (_renderer != null)
+ if (disposing)
{
- _renderer.ElementChanged -= RendererOnElementChanged;
- _renderer.ViewGroup.RemoveOnAttachStateChangeListener(AttachTracker.Instance);
- _renderer = null;
- _context = null;
+ SetElement(_element, null);
+
+ if (_renderer != null)
+ {
+ _renderer.ElementChanged -= RendererOnElementChanged;
+ _renderer.ViewGroup.RemoveOnAttachStateChangeListener(AttachTracker.Instance);
+ _renderer = null;
+ _context = null;
+ }
}
}
diff --git a/Xamarin.Forms.Platform.WP8/VisualElementTracker.cs b/Xamarin.Forms.Platform.WP8/VisualElementTracker.cs
index 2163380..45b51a9 100644
--- a/Xamarin.Forms.Platform.WP8/VisualElementTracker.cs
+++ b/Xamarin.Forms.Platform.WP8/VisualElementTracker.cs
@@ -13,7 +13,15 @@ namespace Xamarin.Forms.Platform.WinPhone
{
public abstract FrameworkElement Child { get; set; }
- public abstract void Dispose();
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ }
public event EventHandler Updated;
@@ -106,29 +114,35 @@ namespace Xamarin.Forms.Platform.WinPhone
}
}
- public override void Dispose()
+ protected override void Dispose(bool disposing)
{
if (_disposed)
return;
+
_disposed = true;
- if (_element != null)
+ if (disposing)
{
- _element.Tap -= ElementOnTap;
- _element.DoubleTap -= ElementOnDoubleTap;
- _element.ManipulationDelta -= OnManipulationDelta;
- _element.ManipulationCompleted -= OnManipulationCompleted;
- }
+ if (_element != null)
+ {
+ _element.Tap -= ElementOnTap;
+ _element.DoubleTap -= ElementOnDoubleTap;
+ _element.ManipulationDelta -= OnManipulationDelta;
+ _element.ManipulationCompleted -= OnManipulationCompleted;
+ }
- if (_model != null)
- {
- _model.BatchCommitted -= HandleRedrawNeeded;
- _model.PropertyChanged -= HandlePropertyChanged;
+ if (_model != null)
+ {
+ _model.BatchCommitted -= HandleRedrawNeeded;
+ _model.PropertyChanged -= HandlePropertyChanged;
+ }
+
+ Child = null;
+ Model = null;
+ Element = null;
}
- Child = null;
- Model = null;
- Element = null;
+ base.Dispose(disposing);
}
protected virtual void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
diff --git a/Xamarin.Forms.Platform.WinRT/VisualElementPackager.cs b/Xamarin.Forms.Platform.WinRT/VisualElementPackager.cs
index 686da58..f2e8794 100644
--- a/Xamarin.Forms.Platform.WinRT/VisualElementPackager.cs
+++ b/Xamarin.Forms.Platform.WinRT/VisualElementPackager.cs
@@ -46,6 +46,12 @@ namespace Xamarin.Forms.Platform.WinRT
public void Dispose()
{
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
if (_disposed)
return;