iphone - iOS CALayer 内存泄漏仅在设备上

标签 iphone ios memory-leaks calayer

Instruments 工具报告 CALayer 的内存泄漏。我有一个自定义类,它是 UIViewController 的子类;在 viewDidLoad() 中,我用 CAGradientLayer 实例化一个 View ,并将该 View 作为当前 View 的 subview 插入,例如:

UIControl *view = [[[UIControl alloc] initWithFrame:CGRectMake(10, 10, 460, 220)] autorelease];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor] CGColor], (id)[[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1.0] CGColor],nil];
gradient.startPoint = CGPointMake(0, 0);
gradient.endPoint = CGPointMake(1, 1);
[view.layer insertSublayer:gradient atIndex:0];
view.layer.masksToBounds = YES;
[view.layer setCornerRadius:5];

[self.view insertSubview:view atIndex:1];

当我在模拟器中运行代码时,一切正常。但是,当我在设备 (iOS 4.3.3) 上运行它时,Instruments 工具报告 CALayer 泄漏。当我注释掉这段代码时,没有泄漏。 这里有什么问题?

编辑:我发现只有当我将 subview 插入到具有 ScrollView 的 View 中时它才会泄漏(所以我的带有渐变层的 subview 插入在 View 和 ScrollView 之间)。

最佳答案

释放 用户界面和 层 因为模拟器在系统配置中运行所以不会出现问题 但与系统相比,设备的内存较少

关于iphone - iOS CALayer 内存泄漏仅在设备上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6223754/

相关文章:

javascript - this.object.property = object.property 是通过引用或值传递的 Javascript;破坏垃圾收集器/内存泄漏

iphone - 多个图像操作导致 iPhone 应用程序崩溃

ios - 为什么 UILabel 的边框在滚动 tableview 后设置?

ios - 滚动 UICollectionView 使用大量内存导致崩溃

ios - 检查 secret 文件是否存在

ios - DJI Mobile sdk - 从 DJI GO App 到个人 App 的遥测

由于 EXC_BAD_ACCESS (SIGSEGV),iOS 7 崩溃。谁能帮我理解崩溃报告?

iphone - UITableView 更新时需要注意什么? (例如锁定它?)

iphone - 如何获取 nsmutablearray 中特定索引的对象

iphone - 删除 iPhone 中的 url 扩展名