2009-09-03 12 views
0

低メモリ状況から復帰した後、クラスの変数が保持する情報はどうなりますか?低メモリ状況(iphone)の持続スキームと状態データ

ビューはアンロードされ、後で再読み込みされますが、ビューを起動したコントローラーによって使用されている補助的なクラス&のデータは保持されていますか?問題の

サンプルシナリオ:

@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 

アプリデリゲートは、一部のユーザーデータとServiceAuthenticatorクラスを作成します(plistファイルから読み込み)とクラスは、リモートサービスをユーザがログに記録されます。 MyAppDelegateのapplicationDidFinishLaunching内部

:ユーザが特定のボタンを押すたびに

- (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' が呼び出されます。ユーザーが(BOOL変数がログイン状態を示す)とそうであればログインしている場合に

-(IBAction)doStuffButtonPressed:(id)sender 
{ 
    [authenticator postData:someDataFromSender]; 
} 

オーセンティケータにターン確認し、リモートサービスとの間でデータの送受信を行います。 ServiceAuthenticatorは、ユーザーの資格情報を一度だけ検証し、その後のオブジェクトへのすべての呼び出しがpostDataになるような種類のクラスです。メモリ不足のシナリオが発生すると、関連するペン先& MyCustomControllerがアンロードされます一度

は - それが再ロードだとき、「ServiceAuthenticator」クラス&元の状態をリセットするためのプロセス何ですか?

実際のモデルクラスのすべてのデータを定期的に保持しています。これらのユーティリティスタイルのクラスで状態データを永続化することも検討する必要がありますか?そのパターンは続くのでしょうか?

+0

誰かが、Webサービス全体でトランザクションを実行するために使用される状態変数を扱うだけで、良いスキームであれば何でも考えていますか? –

答えて

0

ユーティリティクラスでメモリ不足の警告を処理しない場合、データは解放されないため、状態を保持する必要はありません。

関連する問題