使用转换时内存泄漏

时间:2010-09-16 12:53:47

标签: iphone objective-c memory-leaks

当使用此转换超过7-8次时,我发现内存泄漏并崩溃:

-(IBAction)pan1:(id)sender{

    CATransition *transition = [CATransition animation];
    transition.duration = 0.50;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    NSString *types[4] = {kCATransitionFade};
    int rnd = random() % 4;
    transition.type = types[rnd];
    transitioning = YES;
    transition.delegate = self;
    UIImage *image4 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"pan_01_cross_0.png" ofType:nil]];
    pan_cross_0 = [[UIImageView alloc] initWithImage:image4];
    [panView.layer addAnimation:transition forKey:nil];
    [panView addSubview:pan_cross_0]; 
}

1 个答案:

答案 0 :(得分:2)

如果多次运行pan方法,我可以使用pan_cross_0看到至少1次内存泄漏。

pan_cross_0 = [[UIImageView alloc] initWithImage:image4];

您将新图像视图分配到pan_cross_0,但不会从上次释放它。我不确定是什么原因导致崩溃。我至少需要更多细节