I am using ARC. I have a method that runs at the end of a game I have written which should clear up memory. There are a series of objects in an NSMutableArray, which i remove using removeObject:. I then set these objects to nil. However, using NSLog on these objects shows that they still exist. Why does setting them to nil not remove them from memory?
I am using ARC. I have a method that runs at the end of
Share
In ARC (automatic reference counting), setting a reference to an object to
nilmeans two different things depending on the kind of reference you are nil-ing:If it is a
strongreference, then nil-ing it means decreasing the reference count of the referenced object;if it is a
weakreference, nil-ing it does nothing.Thus, nil-ing can lead to different outcomes. Specifically, it is only when the reference count goes to zero that the object is deallocated. This would correspond to a case where no other object in the system is owning the first one (which means holding a
strongreference to it).So, in your case there could be either some other objects keeping a
strongreference to the objects you try tonil; or, you might be nil-ing a weak reference. If you show some code, it may become clearer.