I was wondering how do you remove objects from an NSMutableArray
, cause right now I use [astroids removeFromSuperview];
but it just gets rid of the image on screen but the instance itself is still present even when removed.
views:
410answers:
3NSMutableArray
contains a removeObjectAtIndex
message.
NSMutableArray documentation
-removeFromSuperview is a method of UIView, not NSMutableArray. It seems that the UIView instance you're calling that on is also kept in an MSMutableArray. You will need to use one of the NSMutableArray methods for removing objects on the array itself.
It is necessary to remove it in the array separately because it also owns the object in question, and has retained it independently of its use elsewhere.
NSMutableArray Methods for Removing Objects:
– removeAllObjects
– removeLastObject
– removeObject:
– removeObject:inRange:
– removeObjectAtIndex:
– removeObjectsAtIndexes:
– removeObjectIdenticalTo:
– removeObjectIdenticalTo:inRange:
– removeObjectsFromIndices:numIndices:
– removeObjectsInArray:
– removeObjectsInRange:
Supposing you are removing a view from its superview, then the removeFromSuperview does not send a release message to your view, that would cause it to be immediately freed (if no other objects did retain it).
Instead it sends an autorelease message. This causes the view to actually get removed from memory at the end of the run loop, not immediately after your removeFromSuperview message.