From b87d45fd09919a7edca63d70cc18ef107a554467 Mon Sep 17 00:00:00 2001 From: yunchan Date: Sun, 15 Nov 2026 09:52:53 +0900 Subject: [PATCH] macos: drain an autorelease pool around each frame (Kitedesk T-4204) FlutterRgbaRendererPluginOnRgba runs on the caller's thread, a Kitedesk video thread, which has no autorelease pool and lives as long as the session: an object autoreleased there would stay until the session ends (pointed out in upstream PR #2). Each frame now runs in an @autoreleasepool. On macOS 26.5.2 the frame path autoreleases nothing on that thread, before and after this series (frames_leave_no_autoreleased_objects passes on 50efc18e too), so this is a guard: a probe saw CoreVideo autorelease objects when a process first made an IOSurface on such a thread, and the engine's registrar logs with NSLog for a frame announced to it after its engine is gone, which the old code did on the video thread. Tests: 13 of 13 pass. Co-Authored-By: Claude Opus 5.5 --- macos/Classes/TextureRgbaApi.m | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/macos/Classes/TextureRgbaApi.m b/macos/Classes/TextureRgbaApi.m index 3b4fd37..6dc2812 100644 --- a/macos/Classes/TextureRgbaApi.m +++ b/macos/Classes/TextureRgbaApi.m @@ -4,6 +4,9 @@ // // Created by kingtous on 2023/2/19. // +// Modified by the Kitedesk fork (2026, T-4204): an autorelease pool around +// each frame. +// #import #import "texture_rgba_renderer/texture_rgba_renderer-Swift.h" @@ -14,8 +17,12 @@ extern "C" { /// Keep the same name with Windows. void FlutterRgbaRendererPluginOnRgba(void* texture_rgba_ptr, const uint8_t* buffer, int len, int width, int height, int stride_align) { - TextRgba* texture_rgba = (__bridge TextRgba *)(texture_rgba_ptr); - [texture_rgba markFrameAvaliableRawWithBuffer:buffer len:len width:width height:height stride_align: stride_align]; + // The caller's thread, a session's video thread, has no autorelease pool and + // lives as long as the session. + @autoreleasepool { + TextRgba* texture_rgba = (__bridge TextRgba *)(texture_rgba_ptr); + [texture_rgba markFrameAvaliableRawWithBuffer:buffer len:len width:width height:height stride_align: stride_align]; + } } #if __cplusplus