gpt4 book ai didi

iphone - UIViewController 似乎没有完全随 ARC 发布

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:08:53 26 4
gpt4 key购买 nike

我的应用程序中的第一个 View 只需要显示一次。

我在自定义 segue 中使用以下内容,将其从 Navigation Controllers Stack 中取出并过渡到新的:

- (void)perform {
UINavigationController *nav = [self.sourceViewController navigationController];
NSArray *viewControllers = [NSArray arrayWithObject:self.destinationViewController];
[nav setViewControllers:viewControllers animated:YES];
}

虽然我能够确认调用了 dealloc 方法,但内存使用量并没有下降。我 100% 肯定,内存是由 ViewController 分配的,我希望它会被释放,因为它包含一个相当大的图像 (UIImageView),而另一个 View Controller 很小(内存方面)。

我也确定,我没有在其他任何地方持有对所包含元素的任何引用。

会不会是 UIImageView 将图像保存在内存中,以防再次需要它?

我正在做的事情是否是个好方法? (我的灵感来自 this )

最佳答案

作为快速测试的结果,我推断在 Interface Builder 中设置了图像的 ImageView 似乎在进行一些缓存。我假设它与 imageNamed 使用的缓存机制相同,其 documentation says :

If you have an image file that will only be displayed once and wish to ensure that it does not get added to the system’s cache, you should instead create your image using imageWithContentsOfFile:. This will keep your single-use image out of the system image cache, potentially improving the memory use characteristics of your app.

我不知道有什么方法可以模拟导致缓存被清除的内存压力(除了明显地进行足够的分配以导致实际内存压力)。各种缓存通常不会足够奇怪地响应模拟器的“模拟内存警告”,即使它们确实响应真实的内存压力。 (此外,由于位置服务,您正在物理设备上进行测试。)

但是您可以通过不在 Interface Builder 中设置图像来测试这是否确实是问题,而是以编程方式进行(并且不使用 imageNamed),例如:

NSString *path = [[NSBundle mainBundle] pathForResource:@"imagename" ofType:@"png"];
self.imageView.image = [UIImage imageWithContentsOfFile:path];

在我的测试中,当我关闭在 Interface Builder 中设置图像的场景时,我没有像使用上面的代码那样恢复那么多的内存。

关于iphone - UIViewController 似乎没有完全随 ARC 发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18730137/

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