【问题标题】:Received Memory Warning on iPad在 iPad 上收到内存警告
【发布时间】:2012-07-05 12:52:01
【问题描述】:

我正在 iPad 上开发一个只有动画的应用程序。我正在使用大约 400 张 JPEG 图像来制作动画。大小对应于 7MB。但是动画在 50 幅图像后停止并且应用程序崩溃。我在 NIB 中使用 UIImageView 作为 IBOutlet 并使用 NSTimer 更改代码中的图像。应用程序崩溃并显示消息已收到内存警告。我使用 Instruments 工具检查过,没有发现任何泄漏。

欢迎提出任何建议。

代码

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self callTimer];
}

-(void) callTimer
{
tempView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
[self.view addSubview:tempView];
animationTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self     selector:@selector(animateCharacter) userInfo:nil repeats:YES];
}

-(void) animateCharacter
{
imageNumber++;
if(imageNumber <= 400)
{
    tempView.image = [UIImage imageNamed:[NSString stringWithFormat:@"body%d.jpg",imageNumber]];

}
else
{
    //tempView.image = [UIImage imageNamed:[NSString stringWithFormat:@"pose.png",imageNumber]];
    imageNumber = 0;
    tempImageNumber = 0;
    [tempView removeFromSuperview];
    [tempView release];
    tempView = nil;
    [animationTimer invalidate];
    animationTimer = nil;
}

}

【问题讨论】:

  • 这意味着您可以添加无限时间的图像视图,以便问题出现您只需将图像更改为图像视图。这样你的问题就可以解决了

标签: iphone ios memory warnings


【解决方案1】:

您是否使用多个 Timer 来更改特定持续时间的图像?

根据我的经验,您需要实时使计时器无效并将时间值为零,这样它才能解决您的问题。

您还可以在此处输入代码以获取更多信息,以便我们更多地识别您的问题。

谢谢。

【讨论】:

    【解决方案2】:

    如果您的计时器无效或为零,则您的计时器不会无效或为零,那么您不会收到内存警告。

    animationTimer=nil; [animationTimer 无效];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-28
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多