【问题标题】:Mediapipe: How to properly dealloc MPPGraphMediapipe:如何正确释放 MPPGraph
【发布时间】:2026-02-20 01:05:02
【问题描述】:

我不清楚如何正确停止和解除分配 MPPGraph。我创建了一个与this 非常相似的框架。每次以某种方式调用 dealloc 时都会引发此异常。 Thread 1: Exception: "waitUntilDoneWithError: should not be called on the main thread".

我不知道如何不在主线程中调用它,并希望有人对此有所了解。

Here 你可以找到调用 mediapipe 框架的 swift 代码。此示例是使用可在here 找到的框架创建的。

【问题讨论】:

    标签: mediapipe


    【解决方案1】:

    对于遇到相同问题的任何人。此问题已在here 得到解决,并已提出解决方案。

    编辑: 最后一点可能是错误的,但我以这种方式使用了 dealloc:

    - (void)dealloc {
      self.mediapipeGraph.delegate = nil;
      [self.mediapipeGraph cancel];
      // Ignore errors since we're cleaning up.
      [self.mediapipeGraph closeAllInputStreamsWithError:nil];
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self.mediapipeGraph waitUntilDoneWithError:nil];
      });
    }
    

    【讨论】:

    • 您是否能够解决问题,按照链接中的解决方案并不能解决问题。您能否在此处发布您的解决方案或您可能遵循的步骤?
    • 我用一些代码更新了答案,显示了我最终如何实现解除分配
    • 感谢您更新答案,我会尝试相同的