I'm pretty new to Objective-C and i have lots of troubles with memory management and still i understand a little. If i have an object, NSArray * myArray for example, and i do this
myArray = [[NSArray alloc] initWithObjects:obj1,obj2,obj3,nil];
then i'm doing something and i want myArray to contain new objects and then i init it again
[myArray initWithObjects:obj4,obj5,obj6, nil];
seems like it does what i need but is it correct grom the point of view of memory management?does it increase retain count? should i release it twice then?
Don't do that!
In general, if you want to reset the objects or things inside an already existing Objective C object, create and use some kind of Setter method.
For your array, again do not do this! The "initWithObjects" method you cite is a convenience to initialize a immutable (non-changeable) array with the items an array will be populated with over it's entire lifetime.
For what you are trying to do, just use NSMutableArray. The documentation for it is listed below:
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html
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