Reputation: 3
NSArray * array = [[[NSUserDefaults standardUserDefaults] objectForKey:@"Top"] mutableCopy];
NSString * cellValue = [array objectAtIndex:indexPath.row];
and I get this error:
potential leak of an object stored into "array"
How can I fix this without migrating to ARC. Please help, and thanks a million in advance!
Upvotes: 0
Views: 1555
Reputation: 100190
Because you're creating a new object (methods with copy
give object with reference count 1) you need to release it.
The error refers to the array stored in the array
variable. If you're not using it outside this function or you're later assigning it to a property that would retain it, then autorelease it:
NSArray *array = [[[[NSUserDefaults standardUserDefaults] objectForKey:@"Top"] mutableCopy] autorelease];
Upvotes: 4