summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2016-09-21 22:04:36 (GMT)
committerRui Marinho <me@ruimarinho.net>2016-09-21 22:04:36 (GMT)
commit74cb5c4a97dcb123eb471f6b1dffa1267d0305aa (patch)
treed463831cc17cba1ddfb4ba977cdc6054597ed61a /Xamarin.Forms.Platform.Android
parentd4efe0a37ea87967e38a7d0325df8d84e1c125fc (diff)
downloadxamarin-forms-74cb5c4a97dcb123eb471f6b1dffa1267d0305aa.zip
xamarin-forms-74cb5c4a97dcb123eb471f6b1dffa1267d0305aa.tar.gz
xamarin-forms-74cb5c4a97dcb123eb471f6b1dffa1267d0305aa.tar.bz2
Implement dispose pattern correctly to support derived classes (#364)
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/VisualElementPackager.cs7
-rw-r--r--Xamarin.Forms.Platform.Android/VisualElementTracker.cs24
2 files changed, 24 insertions, 7 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;
+ }
}
}