Skip to content

Commit

Permalink
Change GCD Leak Test
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-szyszkowski committed Jul 1, 2021
1 parent 20b8887 commit 0f8e29f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Spec/GCDTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ import XCTest
class GCDTest: XCTestCase {
func testScheduledBlockHandleDerefsBlockAfterInvoke() {
let invokedExpectation = self.expectation(description: "scheduled block invoked")
let obj = NSObject()

var scheduledBlock = artDispatchScheduled(0, .main) {
_ = obj

var object = NSObject()
weak var weakObject = object

var scheduledBlock = artDispatchScheduled(0, .main) { [object] in
_ = object
invokedExpectation.fulfill()
}

_ = scheduledBlock

waitForExpectations(timeout: 2, handler: nil)

_ = scheduledBlock // silence warning
scheduledBlock = nil

XCTAssertEqual(CFGetRetainCount(obj), 1)
object = NSObject()
XCTAssertNil(weakObject)
}
}

2 comments on commit 0f8e29f

@maratal
Copy link
Collaborator

@maratal maratal commented on 0f8e29f Jul 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would mark each line with retain/release counter, such as "+1 to scheduledBlock, total = 2". Otherwise it's very frustrating to read this with a fresh eye.

@lukasz-szyszkowski
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would mark each line with retain/release counter, such as "+1 to scheduledBlock, total = 2". Otherwise it's very frustrating to read this with a fresh eye.

why? In this solution, we don't need to check to retainCounter, this was in the previous solution and it was doubtful.

Please sign in to comment.