Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to release objects associated via objc_setAssociatedObject?

Tags:

objective-c

If I use a category which uses objc_setAssociatedObject to add pseudo-properties to an object, how can I make sure they get released properly? Do I have to release them manually in dealloc ?

like image 794
radiospiel Avatar asked Feb 14 '12 15:02

radiospiel


1 Answers

Although you answered your own question, still, since you didn't include the docs text itself, and the page you linked to is no longer available, here it is for convenience of others:

From Apple's Objective-C Runtime Reference

void objc_removeAssociatedObjects(id object)

Removes all associations for a given object.

The main purpose of this function is to make it easy to return an object to a "pristine state”. You should not use this function for general removal of associations from objects, since it also removes associations that other clients may have added to the object. Typically you should use objc_setAssociatedObject with a nil value to clear an association.

like image 123
user1244109 Avatar answered Oct 22 '22 17:10

user1244109