低内存情况下的持久性方案和状态数据(iphone)

低内存情况下的持久性方案和状态数据(iphone),iphone,objective-c,memory,memory-management,Iphone,Objective C,Memory,Memory Management,从内存不足的情况返回后,类变量所持有的状态信息会发生什么变化 我知道视图将被卸载,然后在以后重新加载,但是启动视图的控制器所使用的一些辅助类和数据呢 有关的示例场景: @interface MyCustomController: UIViewController { ServiceAuthenticator *authenticator; } -(id)initWithAuthenticator:(ServiceAuthenticator *)auth; // the user ma

从内存不足的情况返回后,类变量所持有的状态信息会发生什么变化

我知道视图将被卸载,然后在以后重新加载,但是启动视图的控制器所使用的一些辅助类和数据呢

有关的示例场景:

@interface MyCustomController: UIViewController
{
    ServiceAuthenticator *authenticator;
}

-(id)initWithAuthenticator:(ServiceAuthenticator *)auth;

// the user may press a button that will cause the authenticator
// to post some data to the service.
-(IBAction)doStuffButtonPressed:(id)sender;
@end

@interface ServiceAuthenticator
{
   BOOL hasValidCredentials; // YES if user's credentials have been validated
   NSString *username;
   NSString *password; // password is not stored in plain text
}

-(id)initWithUserCredentials:(NSString *)username password:(NSString *)aPassword;

-(void)postData:(NSString *)data; 
@end
应用程序委托使用从plist文件读取的一些用户数据创建ServiceAuthenticator类,该类使用远程服务记录用户

在MyAppDelegate的应用程序IDFinishLaunching中:

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{

   ServiceAuthenticator *auth = [[ServiceAuthenticator alloc] initWithUserCredentials:username password:userPassword];

   MyCustomController *controller = [[MyCustomController alloc] initWithNibName:...];
   controller.authenticator = auth;

   // Configure and show the window
   [window addSubview:..];  

   // make everything visible
   [window makeKeyAndVisible];

}
然后,每当用户按下某个按钮时,就会调用“MyCustomController的doStuffButtonPressed”

-(IBAction)doStuffButtonPressed:(id)sender
{
   [authenticator postData:someDataFromSender];
}
验证器依次检查用户是否登录BOOL变量指示登录状态,如果是,则与远程服务交换数据。ServiceAuthenticator是一种只验证用户凭据一次的类,对该对象的所有后续调用都将是对postData的调用

一旦出现内存不足的情况,关联的nib和MyCustomController将被卸载-当它重新加载时,重置“ServiceAuthenticator”类及其以前的状态的过程是什么


我定期将所有数据持久化到实际的模型类中。我是否应该考虑在这些实用工具样式类中持久化状态数据?这就是要遵循的模式吗?

如果您不在实用程序类中处理内存不足警告,那么数据不会被释放,因此您不必保持它们的状态。

有人想到一个好的方案,至少可以处理用于跨web服务执行事务的状态变量吗?