Skip to content

Commit

Permalink
perf(memory-leaks): introduce EventSubscription.Callback property to …
Browse files Browse the repository at this point in the history
…make sure it's not garbage collected before it's invoked
  • Loading branch information
LSViana committed Oct 3, 2023
1 parent b9bfe6c commit f62969a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion YDotNet/Document/Events/EventSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ public class EventSubscription
/// Initializes a new instance of the <see cref="EventSubscription" /> class.
/// </summary>
/// <param name="id">The ID used to identify this instance of <see cref="EventSubscription" />.</param>
internal EventSubscription(uint id)
/// <param name="callback">The callback to be invoked when the related event is triggered.</param>
internal EventSubscription(uint id, Delegate callback)
{
Id = id;
Callback = callback;
}

/// <summary>
/// Gets the ID used to identify this subscription in the document.
/// </summary>
public uint Id { get; }

/// <summary>
/// Gets the callback to be invoked when the related event is triggered.
/// </summary>
/// <remarks>
/// A reference to the callback is stored to make sure it's not disposed by the GC before the unsubscription.
/// </remarks>
public Delegate Callback { get; }
}

0 comments on commit f62969a

Please sign in to comment.