Skip to content

Commit 9888741

Browse files
committed
Fix memory leak in BuildSystemManagerTests
The delegate of a `BuildSystem` is the `BuildSystemManager` itself, which causes a retain cycle if `BuildSystem` is a strong reference. All other build systems implement this as a weak var.
1 parent b3d2df7 commit 9888741

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

Sources/SKCore/BuildSystem.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ public protocol BuildSystem: AnyObject {
5252
/// Path remappings for remapping index data for local use.
5353
var indexPrefixMappings: [PathPrefixMapping] { get async }
5454

55-
/// Delegate to handle any build system events such as file build settings
56-
/// initial reports as well as changes.
55+
/// Delegate to handle any build system events such as file build settings initial reports as well as changes.
56+
///
57+
/// The build system must not retain the delegate because the delegate can be the `BuildSystemManager`, which could
58+
/// result in a retain cycle `BuildSystemManager` -> `BuildSystem` -> `BuildSystemManager`.
5759
var delegate: BuildSystemDelegate? { get async }
5860

5961
/// Set the build system's delegate.

Sources/SKCore/BuildSystemDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import BuildServerProtocol
1313
import LanguageServerProtocol
1414

15-
/// Handles build system events, such as file build settings changes.
15+
/// Handles build system events, such as file build settings changes.
1616
public protocol BuildSystemDelegate: AnyObject {
1717
/// Notify the delegate that the build targets have changed.
1818
///

Tests/SKCoreTests/BuildSystemManagerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ class ManualBuildSystem: BuildSystem {
429429

430430
var map: [DocumentURI: FileBuildSettings] = [:]
431431

432-
var delegate: BuildSystemDelegate? = nil
432+
weak var delegate: BuildSystemDelegate? = nil
433433

434434
func setDelegate(_ delegate: SKCore.BuildSystemDelegate?) async {
435435
self.delegate = delegate

0 commit comments

Comments
 (0)