views:

35

answers:

1

Hi everyone !

There's something i don't seem to get about properties and memory management with iOS !

In my AppDelegate, i want a NSString * property :
- i've declared it this way in the .h file : @property (nonatomic, copy) NSString *myString;
- and synthetized it in the .m

One of my method use the property like this :
myString = [notificationDictionary objectForKey:@"myKey"];
(notificationDictionary being the NSDictionary * I got in the application:didFinishLaunchingWithOptions:'s launchOptions dictionary with the key UIApplicationLaunchOptionsRemoteNotificationKey)

I think that means that my AppDelegate owns its own copy of myString with a retain count to 1, right ?

Then another method tries to access the property, but I get an EXC_BAD_ACCESS exception.

To be 100% sure of what was going on, I've retained my property many times and displayed the value of its retain count at each access : the retain count is decremented somewhere between the method where I give a value to my property and the method where I read it.

Which object sent the release method to my string ?

+4  A: 
e.James
Wow ! Thanks again ! That was something I really need to know ! :)(and although I think the Apple documentation is really well done for their API, I think their documentation about basic Objective-C concepts are hard to find and quite allusive).Anyway, thanks again !
Dirty Henry
No worries! `:)` If you're looking for some reading material on the basic concepts, a good place to start is Apple's memory management guide: http://developer.apple.com/mac/library/documentation/cocoa/conceptual/MemoryMgmt/MemoryMgmt.html
e.James