我是 Objective-C 编程的新手,我遇到了典型的内存问题。我必须做一个基于导航控制器的应用程序,并且在传递少量视图时(使用推送视图控制器),加载 100 个图像的动画。在模拟器中效果很好,但在手机上却不行……我打开了不同的动画,然后它就关闭了。我正在使用 arc 来避免这种情况,但它似乎不起作用。我也尝试禁用弧并手动释放 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 =@
[[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];
}
知道为什么会发生吗?感谢你们对我的帮助!