Search code examples
iosobjective-ckeychainitemwrapper

Property deallocated while app stayed in memory


I am saving username/password info to keychain upon a user logging in. Later if I need the username I get the username from the keychain. I noticed this morning when navigating my app that my keychain property has apparently been deallocated from memory even though the app never was deallocated (never got kicked out to initial view controller upon re-opening app).

I am using this ARCified KeychainItemWrapper, and I think the issue might be the way that I declared the property attribute:

@property (nonatomic, retain) KeychainItemWrapper *keychainItem;

I now know that I should be using strong and not retain, but is that the reason that the property was deallocated before my app?


Solution

  • A. It is not important which the class you are using. The important thing is that your property is deallocated. This happen when there are no anymore objects that have the ownership of the object represented from that property. This means that the object where you declared that property is been deallocated (i.e. a view controller dismissed or popped out);

    B. retain and strong are exactly the same, but being retain and release no longer called with ARC is a good practice use strong.