I create my NSMUtableArray the following way:
self.myArray = [NSMutableArray array];
for (int i = 0; i < number; i++) {
[self.myArray addObject:[NSNull null]];
}
I then add an object to the array at a given index like this:
[self.myArray replaceObjectAtIndex:myIndex withObject:myObj];
Because myArray contains objects of rather large size (images), I want to be able to release the memory by releasing unused objects (myArray holds the data of images to be used in a UIScrollView).
What would be the correct way to release a member of NSMutableArray at a given index? I was thinking of using:
[self.myArray replaceObjectAtIndex:myIndex withObject:[NSNull null]];
The array will release whatever object is currently at that index when you replace the object. So if you replace your big object with something like [NSNull null] that should do what you want.
Note that the memory for the object that as released won’t actually be freed unless the retain count goes to 0. If there are other references to the object i.e. any other place in the code where you’ve retained it, then it will stick around. If the array is the only thing retaining the object, you should be good to go.