gpt4 book ai didi

ios - 为内存释放 UIImageViews

转载 作者:行者123 更新时间:2023-11-28 21:47:28 28 4
gpt4 key购买 nike

我会多次调用这个方法:

-(void)entityMaker {
UIImageView *entity;

NSUInteger image = [self getRandomNumberBetween:0 to:1];
NSUInteger xPosition = [self getRandomNumberBetween:20.0 to:self.width - 20.0];

entity = [[UIImageView alloc] initWithFrame:CGRectMake(xPosition, 20, 20, 20)];
[entity setImage:[self.imageArray objectAtIndex:image]];
[self.view addSubview:entity];

[self performSelector:@selector(animate:) withObject:entity afterDelay:2.0];
}

-(void)animate:(UIImageView *)image {
[image release];
//release has been deprecated
}

但是,我不想让数百万张图片停留在屏幕上。

我怎样才能摆脱它们(在任何设定的秒数之后),以便它们不再占用内存或不再显示?

最佳答案

如果您没有对 ImageView 的强引用(您在发布的代码中没有),它将在您从其父 View 中删除后被释放。

-(void)animate:(UIImageView *)image {
[image removeFromSuperview];
}

关于ios - 为内存释放 UIImageViews,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29583880/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com