NSMutableArray *myArray = [[NSMutableArray alloc] init];
MyClass *obj1 = [[MyClass alloc] init];
[myArray addObject: obj1];
How to clean the old obj1 reference here, if I want to reuse the variable name. Without destroying anything in the array.
obj1 = nil
OR
[obj1 release];
// What is the differences?
obj1 = [[MyClass alloc] init];
[myArray addObject: obj1];
………..
Continue using obj1 and add in array.
When you add an object to array, array stores the variable address, so you can freely use your temporary variable(
obj1) to create another object – the value in the array won’t be destroyed.But since array retains its elements for proper memory management you need to release
obj1after pushing it to array. So you need[obj1 release];line