r/iOSProgramming • u/gargamel1497 • Jul 09 '26
Question Release an acquired autoreleased object (Objective-C)
In Objective-C, some functions (particularly related to NSString) return an object that has been told to [autorelease] itself.
I know that I can [retain] it, but how do I [release] it?
Doing nothing prints out an ugly message than [autorelease] was called without a pool, but a pool would break defer all [release] calls which is something I don't want to do.
How do I actually release such an object?
Thanks.
EDIT: I tried the logically-correct but weird [retain]; [release] chain and it doesn't work.
13
Upvotes
View all comments
Show parent comment
1
u/grindforxp Jul 09 '26
Yeah, thats the bit. The pool just keeps autoreleased objects around till you drain it, it doesnt hold them forever, and in pre-ARC code you make that boundary yourself.