aarti Garg
aarti Garg

Reputation: 161

Object leaked: How can i solve this?

when i copy a NSMutableDictionary object into NSMutableArray object like:

[array addObject:[dictionary copy]];

then i got a memory leak:Method returns an objective-C object with a +1 retain count.

Upvotes: 0

Views: 52

Answers (2)

Shanti K
Shanti K

Reputation: 2918

If you want to avoid autorelease, You can also try this:

NSMutableDictionary temp = [dictionary copy];
[array addObject:temp];
[temp release];

Upvotes: 1

James Webster
James Webster

Reputation: 32066

Both addObject: and copy increase the retain count.

Try [array addObject:[[dictionary copy] autorelease]]

Upvotes: 4

Related Questions