私はiPad用のアプリで働いています。いくつかのビューが表示されるので、メモリ管理に注意する必要があります。
私の問題は自動解放オブジェクトに関連しています。NSAutoreleasePoolを各ViewControllerに関連付けたいと思います。このようなもの:
MyViewController.h
@interface MyViewController: UIViewController
@property (nonatomic, retain) NSAutoreleasePool *myPool;
MyViewController.m
@implementation MyViewController
@synthesize myPool;
- (void) viewDidLoad {
myPool = [[NSAuroteleasePool alloc] init];
}
- (void) dealloc {
[myPool drain];
}
NSAutoreleasePoolをプロパティとして使用することはできません。このような振る舞いを実現したいと思います。何か案が?前もって感謝します。
編集
ご回答ありがとうございます。あなたの質問に答えて(私はまだ私の質問に答えることができません):
viewControllerは、さらに多くのことを実行し、イベントなどに応答します。私が望むのは、これらすべての操作の後で、自動解放されるべきものを解放することです。例を拡張する:
MyViewController.h
@interface MyViewController: UIViewController
@property (nonatomic, retain) NSAutoreleasePool *myPool;
MyViewController.m
@implementation MyViewController
@synthesize myPool;
- (void) viewDidLoad {
myPool = [[NSAuroteleasePool alloc] init];
}
- (IBAction) whatEver: (id) sender {
UIImage *img = [UIImage imageWithData: ...];
NSString *str = @"MyString";
...
}
- (void) dealloc {
[myPool drain];
}
ここで、文字列と画像はどうなりますか?プールに残っていると思いますよね?mainメソッドでリリースプールを待つこともできますが、アプリケーションが終了すると解放されると思います。