Xetius
Xetius

Reputation: 46834

To retain or not to retain

If I am adding an item to a dictionary like this:

[connectionHandlers setObject:projectsHandler forKey:[NSNumber numberWithInt:PROJECTS_CONNECTION_ID]];

Should I be retaining the NSNumber used for the key.

Also, when an object is added to an NSArray or NSDictionary, is it retained by the Array or Dictionary when added and released when removed?

I'm trying to get my head around Memory Management on the iPhone, and it's a doozy

Upvotes: 1

Views: 585

Answers (1)

coneybeare
coneybeare

Reputation: 33101

You do not need to retain it. Anytime you add keys or objects to dictionaries or arrays, the array or dictionary will retain it. If you retain it as well, it will be unnecessary.

Upvotes: 3

Related Questions