diff --git a/iOS/Debugger/Core/DebuggerEngine.swift b/iOS/Debugger/Core/DebuggerEngine.swift index b7c1796..8b1aea3 100644 --- a/iOS/Debugger/Core/DebuggerEngine.swift +++ b/iOS/Debugger/Core/DebuggerEngine.swift @@ -291,10 +291,13 @@ public final class DebuggerEngine { // MARK: - Private Methods private func setupExceptionHandling() { - // Set up exception handling - NSSetUncaughtExceptionHandler { exception in - Self.shared.handleException(exception) - } + // Set up exception handling with a static function to avoid capturing self + NSSetUncaughtExceptionHandler(DebuggerEngine.handleUncaughtException) + } + + // Static exception handler that doesn't capture self + private static func handleUncaughtException(_ exception: NSException) { + shared.handleException(exception) } private func handleException(_ exception: NSException) { diff --git a/iOS/Operations/CoreML/CoreMLManager.swift b/iOS/Operations/CoreML/CoreMLManager.swift index 2349b2b..fa539cb 100644 --- a/iOS/Operations/CoreML/CoreMLManager.swift +++ b/iOS/Operations/CoreML/CoreMLManager.swift @@ -422,10 +422,7 @@ final class CoreMLManager { } } - // First create an observer variable - var memoryObserverLocal: NSObjectProtocol? - - // Set up memory pressure observer - create the observer first + // Store the observer in a local variable first let memoryObserver = NotificationCenter.default.addObserver( forName: UIApplication.didReceiveMemoryWarningNotification, object: nil, @@ -441,16 +438,14 @@ final class CoreMLManager { } // Remove the observer itself - if let observer = memoryObserverLocal { - NotificationCenter.default.removeObserver(observer) - } + NotificationCenter.default.removeObserver(memoryObserver) self?.isModelLoading = false completion?(false) } - // Store the observer in the local variable after creating it - memoryObserverLocal = memoryObserver + // Store the observer in the array for later cleanup + memoryObservers.append(memoryObserver) // Perform actual loading in background predictionQueue.async { [weak self] in