Browse Source

Merge pull request #3537 from MarchingCube/fix-weak-event-manager-compact

WeakEventHandlerManager: Ensure that weak refs with collected refs are compacted as well.
pull/3546/head
Steven Kirk 7 years ago
committed by GitHub
parent
commit
75739d1316
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/Avalonia.Base/Utilities/WeakEventHandlerManager.cs

9
src/Avalonia.Base/Utilities/WeakEventHandlerManager.cs

@ -183,11 +183,16 @@ namespace Avalonia.Utilities
for (int c = 0; c < _count; c++)
{
var r = _data[c];
TSubscriber target = null;
r.Subscriber?.TryGetTarget(out target);
//Mark current index as first empty
if (r.Subscriber == null && empty == -1)
if (target == null && empty == -1)
empty = c;
//If current element isn't null and we have an empty one
if (r.Subscriber != null && empty != -1)
if (target != null && empty != -1)
{
_data[c] = default;
_data[empty] = r;

Loading…
Cancel
Save