summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.UnitTests
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Core.UnitTests')
-rw-r--r--Xamarin.Forms.Core.UnitTests/BindingUnitTests.cs27
1 files changed, 27 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/BindingUnitTests.cs b/Xamarin.Forms.Core.UnitTests/BindingUnitTests.cs
index c520e929..c28adda9 100644
--- a/Xamarin.Forms.Core.UnitTests/BindingUnitTests.cs
+++ b/Xamarin.Forms.Core.UnitTests/BindingUnitTests.cs
@@ -5,6 +5,7 @@ using System.Globalization;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
using NUnit.Framework;
using CategoryAttribute=NUnit.Framework.CategoryAttribute;
using DescriptionAttribute=NUnit.Framework.DescriptionAttribute;
@@ -2592,6 +2593,32 @@ namespace Xamarin.Forms.Core.UnitTests
}
[Test]
+ public async Task BindingDoesNotStayAliveForDeadTarget()
+ {
+ TestViewModel viewModel = new TestViewModel();
+ WeakReference bindingRef;
+
+ {
+ var binding = new Binding("Foo");
+
+ var button = new Button();
+ button.SetBinding(Button.TextProperty, binding);
+ button.BindingContext = viewModel;
+
+ bindingRef = new WeakReference(binding);
+ }
+
+ Assume.That(viewModel.InvocationListSize(), Is.EqualTo(1));
+
+ //NOTE: this was the only way I could "for sure" get the binding to get GC'd
+ GC.Collect();
+ await Task.Delay(10);
+ GC.Collect();
+
+ Assert.IsFalse(bindingRef.IsAlive, "Binding should not be alive!");
+ }
+
+ [Test]
public void BindingCreatesSingleSubscription ()
{
TestViewModel viewmodel = new TestViewModel();