Skip to content

Commit

Permalink
fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
omochi committed Jan 13, 2019
1 parent 7ad0a27 commit 633fdc3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/OrderedDictionary/LinkedListObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class LinkedListObject<T> {

internal weak var owner: LinkedListObject?
internal var next: Node?
internal var previous: Node?
internal weak var previous: Node?

internal init(_ value: T,
owner: LinkedListObject?)
Expand Down
25 changes: 25 additions & 0 deletions Tests/OrderedDictionaryTests/LinkedListObjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,29 @@ class LinkedListObjectTests: XCTestCase {

XCTAssertEqual(revActual, expected.reversed(), file: file, line: line)
}

class Obj {
static var count: Int = 0

init() {
Obj.count += 1
}

deinit {
Obj.count -= 1
}
}

func testLeak() {
do {
let a = LinkedListObject<Obj>()

a.append(Obj())
a.append(Obj())

XCTAssertEqual(Obj.count, 2)
}

XCTAssertEqual(Obj.count, 0)
}
}
1 change: 0 additions & 1 deletion Tests/OrderedDictionaryTests/LinkedListTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,4 @@ class LinkedListTests: XCTestCase {

XCTAssertEqual(revActual, expected.reversed(), file: file, line: line)
}

}

0 comments on commit 633fdc3

Please sign in to comment.