Skip to content

Commit ea63430

Browse files
committed
Fix memory leak in Tree implementation
- caused by retain cycle between parent and child (parent has a strong reference to child, and child has a strong reference to parent)
1 parent 4daa519 commit ea63430

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Tree/Tree.playground/Contents.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class TreeNode<T> {
44
public var value: T
55

6-
public var parent: TreeNode?
6+
public weak var parent: TreeNode?
77
public var children = [TreeNode<T>]()
88

99
public init(value: T) {

Tree/Tree.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
public class TreeNode<T> {
22
public var value: T
33

4-
public var parent: TreeNode?
4+
public weak var parent: TreeNode?
55
public var children = [TreeNode<T>]()
66

77
public init(value: T) {

0 commit comments

Comments
 (0)