Skip to content

Commit f234120

Browse files
MaxHeimbrockclaude
andcommitted
Release local publication and Rtc source FFI handles on cleanup
After the previous commit, Room cleanup walked participants and disposed their handles, including the publication handles for remote tracks. Three local-side handles still leaked on every disconnect: - LocalTrackPublication never wrapped its FFI handle. When PublishTrack succeeded, OnPublish constructed the C# publication from the proto info alone and dropped e.Publication.Handle on the floor. The Rust side kept the entry alive in the FFI handle table for the rest of the process. - RtcVideoSource and RtcAudioSource owned an FFI source handle but their Dispose(bool) implementations released the preview texture, capture buffer, and pending audio frames without ever disposing the handle. The source therefore stayed registered with Rust until the SafeHandle finalizer eventually ran. Wrap the publication handle in the PublishTrackInstruction callback and dispose it through the existing DisposeHandles cascade. Add Handle disposal to the two Rtc source Dispose(bool) overrides so the Meet sample's CleanUpAllTracks now actually frees them. With this change, disconnecting after publishing local mic + camera returns the FFI handle table to its pre-connect baseline on macOS. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c9ef0ae commit f234120

4 files changed

Lines changed: 13 additions & 2 deletions

File tree

Runtime/Scripts/Participant.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ internal void OnPublish(PublishTrackCallback e)
624624

625625
IsError = !string.IsNullOrEmpty(e.Error);
626626
IsDone = true;
627-
var publication = new LocalTrackPublication(e.Publication.Info);
627+
var publication = new LocalTrackPublication(e.Publication.Info, FfiHandle.FromOwnedHandle(e.Publication.Handle));
628628
publication.UpdateTrack(_localTrack as Track);
629629
_localTrack.UpdateSid(publication.Sid);
630630
_internalTracks.Add(e.Publication.Info.Sid, publication);

Runtime/Scripts/RtcAudioSource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ protected virtual void Dispose(bool disposing)
294294
}
295295
_pendingFrameData.Clear();
296296
}
297+
Handle?.Dispose();
297298
_disposed = true;
298299
Utils.Debug($"{DebugTag} disposed");
299300
}

Runtime/Scripts/RtcVideoSource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ protected virtual void Dispose(bool disposing)
211211
Debug.Log("Disposing capture buffer");
212212
_captureBuffer.Dispose();
213213
}
214+
Handle?.Dispose();
214215
_disposed = true;
215216
}
216217

Runtime/Scripts/TrackPublication.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,17 @@ public sealed class LocalTrackPublication : TrackPublication
9696
{
9797
public new ILocalTrack Track => base.Track as ILocalTrack;
9898

99-
internal LocalTrackPublication(TrackPublicationInfo info) : base(info)
99+
private FfiHandle Handle;
100+
101+
internal LocalTrackPublication(TrackPublicationInfo info, FfiHandle handle) : base(info)
100102
{
103+
Handle = handle;
104+
}
105+
106+
internal override void DisposeHandles()
107+
{
108+
base.DisposeHandles();
109+
Handle?.Dispose();
101110
}
102111
}
103112
}

0 commit comments

Comments
 (0)