Skip to content

Commit 8d08728

Browse files
committed
fix(inference): Swift 6 Sendable + deprecated API cleanup on main
- InferenceEngine.observers: nonisolated(unsafe) to silence Swift 6 deinit isolation false-positive on NSObjectProtocol array - Restore backgroundedModelId property (dropped during refactor) - GPU.set(cacheLimit: 0) → Memory.cacheLimit = 0 (deprecated API)
1 parent f2065f3 commit 8d08728

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Sources/MLXInferenceCore/InferenceEngine.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ public final class InferenceEngine: ObservableObject {
7474
private var generationTask: Task<Void, Never>?
7575

7676
// All NotificationCenter observers collected for clean deregistration
77-
private var observers: [NSObjectProtocol] = []
77+
// nonisolated(unsafe): populated exclusively from MainActor init, read only in deinit
78+
// after all strong references have dropped — no concurrent access possible.
79+
// Declared nonisolated(unsafe) to satisfy Swift 6 deinit isolation rules.
80+
nonisolated(unsafe) private var observers: [NSObjectProtocol] = []
7881

79-
// Track the model ID that was active before we backgrounded,
80-
// so we can restore it when returning to foreground.
82+
// Tracks the model ID active before app backgrounding so we can restore it on foreground.
8183
private var backgroundedModelId: String?
8284

8385
public init() {
@@ -264,7 +266,7 @@ public final class InferenceEngine: ObservableObject {
264266
currentModelId = nil
265267
state = .idle
266268
ExpertStreamingConfig.shared.deactivate()
267-
MLX.GPU.set(cacheLimit: 0)
269+
MLX.Memory.cacheLimit = 0
268270
}
269271

270272
// MARK: — Generation

0 commit comments

Comments
 (0)