我在创建一款iPad应用程序时遇到了一些麻烦。有一个简单的图像序列/动画约80帧在一个点。这个泄漏在哪里? /为什么我有内存问题?
的代码看起来是这样的(这是一个UIView子类的子类):
- (id)init {
UIImage *theImage = [UIImage imageNamed:@"chart0075.jpg"];
// get the frame
CGRect lgeFrame = CGRectMake(20, 130, theImage.size.width, theImage.size.height);
// set the new frame
CGFloat newHeight = theImage.size.height/1.65;
CGFloat newWidth = theImage.size.width/1.65;
CGRect smlFrame = CGRectMake(480, 200, newWidth, newHeight);
self = [super initWithLargeFrame:lgeFrame smallFrame:smlFrame];
if(self){
// lets add the image as an image view
theImageView = [[UIImageView alloc] initWithImage:theImage];
[theImageView setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[theImageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[self addSubview:theImageView];
// now we need to make an array of images for the image sequence
NSMutableArray *imageSeq = [NSMutableArray array];
for(int i = 1; i < 76; i++){
NSString *jpgnumber;
if(i<10){
jpgnumber = [NSString stringWithFormat:@"000%i",i];
}
else {
jpgnumber = [NSString stringWithFormat:@"00%i",i];
}
NSString *imageFile = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"chart%@",jpgnumber] ofType:@"jpg"];
[imageSeq addObject:[UIImage imageWithContentsOfFile:imageFile]];
}
[theImageView setAnimationImages:imageSeq];
[theImageView setAnimationDuration:1.5];
[theImageView setAnimationRepeatCount:1];
}
return self;
}
然后在一个反向捏合手势的图像应该动画。我第一次做这个反向捏手势需要几秒钟来开始动画。有时我得到一个内存警告级别1,该应用程序将崩溃。
这里有什么问题?一次80马力的记忆太多了吗?他们总共大大低于2MB,所以他们肯定不应该填满iPad的记忆吗?
我已经看到它与分配工具,这是建议我在动画时在内存中约40kb,但随后这回落到0在随后的动画。 (尽管分配工具确实让我感到困惑)。
有没有人有任何想法是什么造成这个?我可以发布更多的代码或任何必要的东西?
感谢很多:)
我不知道它是否有帮助,但我会移动'NSString * jpgnumber;'和'NSString * imageFile;'在for循环之外[见这里](http://stackoverflow.com/questions/5052443) /指针和 - 循环)。此外,我会使用使用'NSMutableArray * imageSeq = [[NSMutableArray alloc] init];'。只要有可能,我就避免使用自动释放的对象。 – fabian789 2011-03-28 16:10:12
你好。我已经让我的可变数组和图像非自动发布,并且我已经将for循环之外的所有指针移动了,但是我仍然遇到了同样的问题...... :(感谢您的帮助 – 2011-03-28 16:15:33