views:

45

answers:

2

In regards to this posting http://stackoverflow.com/questions/1481871/why-does-self-protect-memory-space/1481882#1481882, I'm using 'self' to access aArray. Yet, I still get an invalid object in the didSelectRowAtIndexPath: method.

In the root controller, I access aArray like this:

MyAppDelegate *theDelegate = [[UIApplication sharedApplication] delegate];  
NSString *aKey = [theDelegate.aArray objectAtIndex:0];

Would that have something to do with aArray loosing its reference? Why wouldn't it occur in cellForRowAtIndexPath: (the first use of it outside of MyAppDelegate proper)?

+1  A: 

If aArray is a property that is set to retain, then you may be over-releasing it somewhere. It doesn't seem entirely clear in your question, but if it's the object at index 0 that's invalid, it may be it that was over-released. If you're using Xcode 3.2 on Snow Leopard you may want to make sure you're using the Clang static analyzer. It can help find such over-releases.

Cory Kilger
Yes - I'm running Clang. Object at index zero is valid.
4thSpace
Once the array reference goes bad, instead of see an NSArray, I see "{(int)[$VAR count]} objects". Still trying to track it down.
4thSpace
Was using 'assign' rather than 'retain'. Didn't catch it for a while. Problem solved.
4thSpace
So I guess instead of over-releasing, it was under-retained.
Cory Kilger
+2  A: 

This question doesn't make sense. Or, rather, the answer is still "go read and understand the documentation linked to in the answer to your other question".

Specifically:

There is no magic about memory management. There is nothing special about self vs. any other kind of object reference. The dot notation is merely short hand for a method call; nothing special to it, either.

Until you understand these things, you'll be chasing ghosts and not actually solving the real problems in your code.

bbum