【发布时间】:2015-10-27 01:31:14
【问题描述】:
我正在做一个电子书项目,我也在使用 ARC,但是,当我在模拟器中翻页时,我的内存迅速增长,当我完成翻页时,它已接近 200MB。似乎内存没有被释放,但这不是 ARC 的用途吗?我删除了我的 NSTimer 和所有代表,看看这是否是罪魁祸首,但无济于事。好像我在某个地方有一个保留周期,但我似乎找不到它。我也没有使用积木......有什么想法吗?
编辑:这是一个 UIPageViewController 应用程序
我替换了以下代码
- (DataViewController *)viewControllerAtIndex:(NSUInteger)index storyboard:(UIStoryboard *)storyboard {
// Return the data view controller for the given index.
if (([self.pageData count] == 0) || (index >= [self.pageData count])) {
return nil;
}
// Create a new view controller and pass suitable data.
DataViewController *dataViewController = [storyboard instantiateViewControllerWithIdentifier:@"DataViewController"];
with
- (DataViewController *)viewControllerAtIndex:(NSUInteger)index storyboard:(UIStoryboard *)storyboard {
// Return the data view controller for the given index.
if (([self.pageData count] == 0) || (index >= [self.pageData count])) {
return nil;
}
// Create a new view controller and pass suitable data.
DataViewController *dataViewController = [storyboard instantiateViewControllerWithIdentifier:self.pageData[index]];
其中 self.pageData[index] 是情节提要中视图控制器的 ID。我希望 pageViewController 在请求下一个 viewController 时释放这个 viewController
【问题讨论】:
-
使用“仪器”实用程序查看分配。它可以向您显示存在哪些对象以及它们是在哪里创建的。
-
关于您对 ARC 的评论的快速说明...使用 ARC,编译器将为您处理引用计数并进行内存管理调用...但是如果您是 (无意中)抓住对象,它不会摆脱它们;)我猜
UIPageViewController中的页面很大,这就是内存的积累。就像 Phillip 所说,尝试使用 Instruments 进行调查,或者,只需查看您的代码。您可能会发现错误...(或在您的问题中发布一些错误)。 -
模板和我的应用程序之间的唯一区别是每个页面都是不同的视图控制器,而不是重复使用相同的视图控制器......我也将代码添加到我的问题中
标签: ios objective-c memory memory-management automatic-ref-counting