我是新的Objective-C編程,我有典型的內存問題。我必須做一個基於導航控制器的應用程序,並通過幾個視圖(使用推視圖控制器)時,加載100個圖像的動畫。在模擬器運作良好,但在電話不......我打開不同的動畫,然後關閉。我正在使用弧來避免這種情況,但似乎沒有奏效。我也嘗試禁用弧並手動釋放UIImageView,但它甚至很快崩潰。以下是其中一個視圖的示例:使用弧的內存問題
//.h
@interface Gegant_nou : UIViewController {
IBOutlet UIImageView *ImageViewGegant;
}
@property (nonatomic, strong) UIImageView* ImageViewGegant;
//.m
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *rigthButton = [[UIBarButtonItem alloc] initWithTitle:@"Detalls" style:UIBarButtonItemStyleBordered target:self action:@selector(canviarDetalls)];
self.navigationItem.rightBarButtonItem = rigthButton;
[rigthButton release];
ImageViewGegant.animationImages [email protected]
[[UIImage imageNamed:@"0001.png"],
[UIImage imageNamed:@"0002.png"],
. load all the images
.
[UIImage imageNamed:@"0099.png"],
[UIImage imageNamed:@"0100.png"]];
ImageViewGegant.animationDuration = 4;
ImageViewGegant.animationRepeatCount = 0;
[ImageViewGegant startAnimating];
[self.view addSubview:ImageViewGegant];
self.title = @"Gegant nou";
[ImageViewGegant release];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload{
[super viewDidUnload];
[ImageViewGegant release];
}
任何想法爲什麼會發生?感謝你們對我的幫助!
1.哪一行會拋出異常? 2.在iOS6下不推薦使用'-viewDidUnload',你應該避免使用它(它永遠不會被調用)。 3.爲什麼你不使用循環初始化你的圖像數組? – holex
從使用ImageNamed加載vs initwtihcontentsoffile的內存使用有一些爭議。看到這個職位的一些關於其他選項的更好的信息http://stackoverflow.com/questions/6566827/iphone-ios-how-to-load-a-lot-of-image-in-many-folder-and-show -in-a-table-view –
@holex我應該用什麼來代替viewDidUnload? dealloc的? – joan2404