Hubert Kunnemeyer
Hubert Kunnemeyer

Reputation: 2261

objective c memory and mutable copy

I have a MutableDictionay and I need a copy of all the keys. I'm not sure if I own this. I am copying it via mutableCopy, but I'm not sure what the correct call is in this situation...

The NSMutableDictionary(myDictionary) is an iVar in a UIViewController.

self.myDictionary = [NSMutableDictionary]allc]init];

 //...Add some values and keys to myDictionary....
 //...Then get all the keys.....

NSArray *allKeys = [[myDictionary allKeys]mtableCopy];

Now do I own allKeys? I'm not sure here. Any help is appreciated.

Upvotes: 0

Views: 103

Answers (1)

Sean
Sean

Reputation: 5820

According to the documentation, "The returned object is implicitly retained by the sender, which is responsible for releasing it. The copy returned is mutable whether the original is mutable or not.". So yes, you now own allKeys and are responsible for releasing it.

Upvotes: 2

Related Questions