Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix GCAlloc #985

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

fix: Fix GCAlloc #985

wants to merge 9 commits into from

Conversation

karasusan
Copy link
Collaborator

No description provided.

@aet
Copy link
Contributor

aet commented Oct 9, 2023

Seeing this in the editor occasionally on script reload:

A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Int32, Allocator, NativeArrayOptions) (at /Users/bokken/build/output/unity/unity/Runtime/Export/NativeArray/NativeArray.cs:58)
Unity.WebRTC.Batch:.ctor() (at Library/PackageCache/com.unity.webrtc@642801c9b1/Runtime/Scripts/Context.cs:75)
Unity.WebRTC.Context:.ctor(IntPtr, Int32) (at Library/PackageCache/com.unity.webrtc@642801c9b1/Runtime/Scripts/Context.cs:151)
Unity.WebRTC.Context:Create(Int32) (at Library/PackageCache/com.unity.webrtc@642801c9b1/Runtime/Scripts/Context.cs:138)
Unity.WebRTC.WebRTC:InitializeInternal(Boolean, Boolean, NativeLoggingSeverity) (at Library/PackageCache/com.unity.webrtc@642801c9b1/Runtime/Scripts/WebRTC.cs:736)
Unity.WebRTC.ContextManager:OnAfterAssemblyReload() (at Library/PackageCache/com.unity.webrtc@642801c9b1/Runtime/Scripts/Context.cs:33)
UnityEditor.AssemblyReloadEvents:OnAfterAssemblyReload() (at /Users/bokken/build/output/unity/unity/Editor/Mono/AssemblyReloadEvents.cs:34)

Fixed by

diff --git a/Runtime/Scripts/Context.cs b/Runtime/Scripts/Context.cs
index c8c49f0..3aa38f4 100644
--- a/Runtime/Scripts/Context.cs
+++ b/Runtime/Scripts/Context.cs
@@ -175,6 +175,7 @@ namespace Unity.WebRTC
 
                 // Release buffers on the rendering thread
                 batch.Submit(true);
+                batch.Dispose();
 
                 NativeMethods.ContextDestroy(id);
                 self = IntPtr.Zero;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants