IPhone应用程序崩溃的设备,但工程对iPhone
我在这个初学者:)IPhone应用程序崩溃的设备,但工程对iPhone
我有一个应用程序,它改变时,按下一个按钮一个UIImageView的图像,每幅图像约为200 KB,在运行时在模拟器中运行正常,我可以多次更换图像而不会出现问题。
在我的设备上运行时(ipod touch)它加载正常,它缓慢地通过约4张图像,然后崩溃。当我使用Allocations性能工具运行它时,它会在总字节数达到2.75 megs时崩溃。生活分配的数量大约是8000(这是高吗?)。
我的控制台读取该
Program received signal: “0”.
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")
我使用“泄漏”性能工具也尝试过,并没有发现任何泄漏。
我.h文件中加载图像和uimageview这样的:
@property(retain, nonatomic) IBOutlet UIImageView* myUIImageView;
@property(nonatomic, retain) UIImage *image;
另外,我释放这些是这样的:
- (void)dealloc {
[super dealloc];
[myUIImageView release];
[image release];
}
我还添加了这一点,但它似乎没有有什么区别:
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
[myUIImageView release];
[image release];
// Release any cached data, images, etc that aren't in use.
}
我不知道还有什么要尝试在这一点上,任何调试技巧的建议会不胜感激,如何解决像这样的内存问题的任何指针将非常有帮助, 谢谢!
此外,对不起忘了加上形象改变代码:
- (IBAction)myButton {
static NSUInteger counter = 0;
counter++;
if (counter == 1) {
myUIImageView.image = [UIImage imageNamed:@"image1.jpg"];
}
else {
myUIImageView.image = [UIImage imageNamed:@"image2.jpg"];
counter = 0;
}
}
你的影像变更的代码看起来不错,但我建议这些变化:
您应该设置myUIImageView
为零你viewDidUnload
方法:
- (void)viewDidUnload {
// release retained subviews of main view
self.myUIImageView = nil;
}
在didReceiveMemoryWarning
,你应该设置图像零,而不是发送释放:
self.image = nil;
两个didReceiveMemoryWarning
有[image release]
和dealloc
可能会导致双重版本。
此外,请勿在didReceiveMemoryWarning
中发布myUIImageView
。
你真的使用image
伊娃吗?看起来您正在将图像直接分配给UIImageView
。显然,未使用的伊娃不会引起问题,但我只是想知道为什么它在那里。
是您使用的代码来改变形象?确保你没有重新分配图像或imageview。
感谢您的回应本,请参阅我的编辑。 – 2010-10-08 23:40:59
谢谢你的帮助乔希,我在我的图像改变代码中添加 – 2010-10-08 23:47:33
修改我的答案作为回应。;-) – 2010-10-08 23:51:17
嗯,我不太确定如果我使用伊娃,我在我的.m文件顶部合成图像:@synthesize image;因为它警告我即使它正在编译也不存在,我也应该将myUIImageView设置为didReceiveMemoryWarning中的nil以及图像吗?或者可以在这里发布它。 – 2010-10-08 23:55:59