[AudioUnit] Only create the GCHandle to self when we need it. (#13397)

This commit is contained in:
Rolf Bjarne Kvinge 2021-11-22 08:14:51 +01:00 коммит произвёл GitHub
Родитель 72c369ad7e
Коммит faa966ba20
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 3 добавлений и 1 удалений

Просмотреть файл

@ -312,7 +312,6 @@ namespace AudioUnit
internal AudioUnit (IntPtr handle, bool owns) internal AudioUnit (IntPtr handle, bool owns)
: base (handle, owns) : base (handle, owns)
{ {
gcHandle = GCHandle.Alloc(this);
} }
static IntPtr Create (AudioComponent component) static IntPtr Create (AudioComponent component)
@ -601,6 +600,9 @@ namespace AudioUnit
renderer [audioUnitElement] = renderDelegate; renderer [audioUnitElement] = renderDelegate;
if (!gcHandle.IsAllocated)
gcHandle = GCHandle.Alloc (this);
var cb = new AURenderCallbackStruct (); var cb = new AURenderCallbackStruct ();
cb.Proc = CreateRenderCallback; cb.Proc = CreateRenderCallback;
cb.ProcRefCon = GCHandle.ToIntPtr (gcHandle); cb.ProcRefCon = GCHandle.ToIntPtr (gcHandle);