diff --git a/appveyor.yml b/appveyor.yml index 1aee6bb2cf..2cb5bf6484 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,6 +20,7 @@ configuration: - Release after_test: +- .\packages\JetBrains.dotMemoryUnit.2.1.20150828.125449\tools\dotMemoryUnit.exe -targetExecutable="%xunit20%\xunit.console.x86.exe" -returnTargetExitCode --"tests\Perspex.LeakTests\bin\Release\Perspex.LeakTests.dll" - ps: nuget\build-appveyor.ps1 artifacts: diff --git a/samples/XamlTestApplicationPcl/ViewModels/EditorViewModel.cs b/samples/XamlTestApplicationPcl/ViewModels/EditorViewModel.cs new file mode 100644 index 0000000000..4623a14275 --- /dev/null +++ b/samples/XamlTestApplicationPcl/ViewModels/EditorViewModel.cs @@ -0,0 +1,103 @@ +using Perspex.Threading; + +namespace XamlTestApplication.ViewModels +{ + using ReactiveUI; + using System; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + + public class ShellViewModel : ReactiveObject + { + private ShellViewModel() + { + documents = new ObservableCollection(); + + AddDocumentCommand = ReactiveCommand.Create(); + AddDocumentCommand.Subscribe(_ => + { + Documents.Add(new EditorViewModel()); + }); + + GCCommand = ReactiveCommand.Create(); + GCCommand.Subscribe(_ => + { + GC.Collect(); + }); + } + + public static ShellViewModel Instance = new ShellViewModel(); + + private ObservableCollection documents; + public ObservableCollection Documents + { + get { return documents; } + set { this.RaiseAndSetIfChanged(ref documents, value); } + } + + private EditorViewModel selectedDocument; + + public EditorViewModel SelectedDocument + { + get { return selectedDocument; } + set { this.RaiseAndSetIfChanged(ref selectedDocument, value); } + } + + private int instanceCount; + + public int InstanceCount + { + get { return instanceCount; } + set { this.RaiseAndSetIfChanged(ref instanceCount, value); } + } + + + + public ReactiveCommand AddDocumentCommand { get; } + public ReactiveCommand GCCommand { get; } + } + + public class EditorViewModel : ReactiveObject + { + private static int InstanceCount = 0; + + public EditorViewModel() + { + InstanceCount++; + ShellViewModel.Instance.InstanceCount = InstanceCount; + text = "This is some text."; + + CloseCommand = ReactiveCommand.Create(); + + CloseCommand.Subscribe(_ => + { + ShellViewModel.Instance.Documents.Remove(this); + }); + } + + ~EditorViewModel() + { + + + //System.Console.WriteLine("EVM Destructed"); + InstanceCount--; + Dispatcher.UIThread.InvokeAsync(() => + { + ShellViewModel.Instance.InstanceCount = InstanceCount; + }); + + } + + private string text; + public string Text + { + get { return text; } + set { this.RaiseAndSetIfChanged(ref text, value); } + } + + public ReactiveCommand CloseCommand { get; } + } +} diff --git a/samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs b/samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs index 3ae72e138c..f584493097 100644 --- a/samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs +++ b/samples/XamlTestApplicationPcl/ViewModels/MainWindowViewModel.cs @@ -56,7 +56,11 @@ namespace XamlTestApplication.ViewModels } }; - CollapseNodesCommand = ReactiveCommand.Create(); + + + + + CollapseNodesCommand = ReactiveCommand.Create(); CollapseNodesCommand.Subscribe(_ => ExpandNodes(false)); ExpandNodesCommand = ReactiveCommand.Create(); ExpandNodesCommand.Subscribe(_ => ExpandNodes(true)); @@ -77,6 +81,15 @@ namespace XamlTestApplication.ViewModels ofd.ShowAsync(); }); + shell = ShellViewModel.Instance; + } + + private ShellViewModel shell; + + public ShellViewModel Shell + { + get { return shell; } + set { shell = value; } } public List Items { get; } diff --git a/samples/XamlTestApplicationPcl/Views/MainWindow.xaml b/samples/XamlTestApplicationPcl/Views/MainWindow.xaml index 1dc8575178..594f27bc41 100644 --- a/samples/XamlTestApplicationPcl/Views/MainWindow.xaml +++ b/samples/XamlTestApplicationPcl/Views/MainWindow.xaml @@ -316,6 +316,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + +