tezvyn:

What an autoreleasepool is and when to add one manually

Source: interviewintermediate

WHAT IT TESTS: deferred deallocation under tight loops. OUTLINE: an autorelease pool holds objects until it drains; wrap tight loops creating many temporary ObjC objects in autoreleasepool to cap peak memory. RED FLAG: thinking it relates to ARC retain cycles.

WHAT IT TESTS: understanding deferred release and peak-memory control. ANSWER OUTLINE: an autorelease pool collects objects sent autorelease and frees them only when the pool drains, normally at the end of a run loop iteration. In a long synchronous loop that creates many temporary Objective-C-backed objects, those objects accumulate until the loop ends, spiking memory; wrapping the loop body in autoreleasepool { } drains each iteration and caps the high-water mark. RED FLAG: confusing it with retain cycles or thinking pure-Swift code needs it.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

What an autoreleasepool is and when to add one manually · Tezvyn