Purging an NSArrayController properly


I’d like to replace the contents of a controller before inserting new items. I use ARC, do I don’t have to worry about memory leaks :slight_smile: but I wanted to know the better way to do this (giving that I don’t want to have the content array in my properties if it’s not really useful).

In ASOC it would be:

set myArrayController’s arrangedObjects() to {} //GC will take “care” of the discarded objects.

And in ObjC? For the moment I use:

[myArrayController removeObjects:[myArrayController arrangedObjects]]; :/

I’m using an unique window for multiple documents. In a NSDocument application, as there is one controller per doc, this wouldn’t be necessary.

Is it safe? Is there a better way?


Ok, in the doc I found it’s much more faster to set the contents of a controller rather to remove, add or insert, especially if the new items are to be selected. So:

myArrayController’s setContent_({});


[myArrayController setContent [NSMutableArray array]];

is a way, assuming you have GC enabled for ASOC or ARC for Objective-C. For “I love to manage the memory myself” people, I suppose they have to dealloc the previous content.