Question

I am curious on what happen if I have code like this.

NSArray* myArray = [NSArray alloc]initWithObjects:@"a", @"b", @"c", nil];
[myArray autorelease];
myArray = [otherArray copy];

autorelease would mark the memory to be released at the end of current event loop.

Does that mean [otherArray copy] is released at the end of event loop?

Was it helpful?

Solution

No. When you autorelease objects, the objects are added to the autorelease pool, not the pointer to those objects. You're autoreleasing an array, if you copy another array into that pointer, it will not be affected. You should be using ARC anyway, and not using auto/release.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top