tags:

views:

153

answers:

1

Hello,

I am using the NSUsersDefault to save the state of application when there is any interruption in the app.

What I am doing is that I have created a method "saveState" in my class where the application is running and in this method I am saving all the necessary things in NSUsersDefault, among those things I have few NSString which I am saving like

[prefs setObject:batsman1HowOut forKey:@"batsman1HowOut"];

Now, I am calling "saveState" method from the AppDelegate class -> applicationWillTerminate method.

So, what happens is that when interruption will occur it will come to app delegate class and applicationWillTerminate method will be called and it will than go to the "saveState" method of the class where I am storing everything in NSUsersDefault.

Problem is that when I am trying to save the NSString (like the one above), it is giving me error saying that it is out of scope.

Please help me.

Regards, Pratik

A: 

When the applicationWillTerminate method called, probably the string has been released. Try to release the string, after you saved it to the NSUserDefaults. That will not cause memory leak, since everytime when you close your app, the applicationWillTerminate will be called.

MetaImi