I'm currently doing the following to clear out an NSMutableDictionary
[myDictionary release];
myDictionary = [[NSMutableDictionary alloc] init];
The release line doesn't actually release any objects in the dictionary. I can still see all of them on the next line. It isn't until the alloc line is executed that the dictionary is zeroed out. Is there a better way to do it?
The clear() method removes all the elements from a dictionary.
Python dictionary clear() method is used to remove all elements from the dictionary. When you have a dictionary with too many elements, deleting all elements of the dictionary one after another is a very time taken process, so use clear() method to delete all elements at once rather than deleting elements one by one.
I can't test it at the moment, but have you tried the removeAllObjects
method of NSMutableDictionary
?
http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableDictionary/removeAllObjects
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With