Get the latest tech news

NSCopyObject, the griefer that keeps on griefing


very old Foundation function – pre-dating Mac OS X entirely; from the NeXT era – that was originally basically just memcpy, but now it’s complicated. A lot more complicated.

There’s still prominent guides scattered about the web that push you unequivocally to use retain, which is not just impossible to do directly under ARC, but flat-out wrong even if you do figure out one of the “clever” ways to do it (you’ll end up over-retaining your ARC-managed references, causing memory leaks). Blindly copying the bytes of an object instance, and just hoping that somehow that works correctly – in an object-oriented language derived from Smalltalk where even numbers are often reference types – is farcical. Classes that intend to be subclassed – but also semantically should support copying i.e. NSCopying – have long been making the mistake of thinking that means using NSCopyObject.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of griefer

griefer

Photo of NSCopyObject

NSCopyObject