iOS 图片加载方法不同内存释放问题

//点击删除查看内存释放问题

  • (void)buttonAction:(id)sender {
    // [self.imageView stopAnimating];
    [self.imageView removeFromSuperview];
    self.imageView = nil;
    }

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

    NSMutableArray *arr = [NSMutableArray array];

    //这种方式加载图片 即使imageView释放 图片缓存仍会存在的 图片
    for (NSInteger i = 1; i <= 63; i++) {
    UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.png", i]];
    [arr addObject:image];
    }

    //这种方式加载图片点击button即可见到内存释放
    for (NSInteger i = 1; i <= 63; i++) {
    NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%ld", i] ofType:@"png"];
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    [arr addObject:image];
    }

    self.imageView.animationDuration = 2.5f;
    self.imageView.animationImages = arr;
    [self.imageView startAnimating];

}

你可能感兴趣的:(iOS 图片加载方法不同内存释放问题)