Ver código fonte

Call Compact on Add

Nikita Tsukanov 6 anos atrás
pai
commit
a89b6128dd

+ 3 - 2
src/Avalonia.Base/Utilities/WeakEventHandlerManager.cs

@@ -132,6 +132,7 @@ namespace Avalonia.Utilities
 
             public void Add(EventHandler<T> s)
             {
+                Compact(true);
                 if (_count == _data.Length)
                 {
                     //Extend capacity
@@ -174,7 +175,7 @@ namespace Avalonia.Utilities
                 }
             }
 
-            void Compact()
+            void Compact(bool preventDestroy = false)
             {
                 int empty = -1;
                 for (int c = 0; c < _count; c++)
@@ -193,7 +194,7 @@ namespace Avalonia.Utilities
                 }
                 if (empty != -1)
                     _count = empty;
-                if (_count == 0)
+                if (_count == 0 && !preventDestroy)
                     Destroy();
             }