DevPrep

All topics › Multithreading & concurrency

A setter in non-ARC code

Middle PRO

The essence

The question is about manual memory management (MRC) and thread-safe accessors. An MRC setter must release the old value and retain the new one; a getter must return the object so that it does not die in the caller's hands. If the property is touched from several threads, both operations also need synchronization.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store