I have an NSMutableArray that I store two objects in but they get replaced with nil in the array after a short while. Why is that happening? The array object is still around and shows it contains two objects, but they are both nil.
Doesn't the fact that they are in an array mean they are referenced and should not be deleted?
What is odd is that the objects I placed in the array are not being deleted as they are referenced by other objects, they are just being replaced with nil in the array.
-(void)addRender:(id)theRender
{
if (renderArray == nil)
renderArray = [NSMutableArray array];
// Leaving this function and for a while afterwords, the object is in the array.
// By afterwords, I think is until the autorelease pool is drained, but I can't
// be sure but the objects are there as I am stepping though code.
[renderArray addObject:theRender];
}
-(void)render
{
// By the time this is called, renderArray has 2 nil objects in it.
if (renderArray)
[renderArray makeObjectsPerformSelector:@selector(render)];
}
The -(void)addRender
function is being called from the objects init function. I don't know if that matters, but self is set by then.
The objects themselves are not being deleted, just replaced with nil in the array. What condition causes ARC to do that? I've read about zeroing weak references, which does something like this, but I'm not declaring anything a weak reference, besides, the objects are still around and referenced places.
I've spent the last two hours beating my head against this.
NSMutableArray *renderArray;
– Roger GilbrataddRender:
and the beginning ofrender
and post the results? – Firoze Lafeernil
? (I don't do any iX programming/usage, but most of the time the object can be cleared, but not the pointers to such objects... if there were such pointers they should keep the object alive or now point to an invalid object? Or is there some magic in ARC that escapes me?) – user166390