Derrick Ho
1 min readJul 20, 2018

Im writing this on a mobile device so I can’t verify this, but typically the defer block happens upon deallocation. Deallocation happens at the end of the auto release pool.

__block int n = 0;

@autoreleasepool {

id defer = [MyDefer block:^{

n = 10;

}];

}

XCTAssert(n == 10);

Objects get deallocated at the end of an auto release pool so instead of using an implicit one I make it explicit.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response