为什么我的 ModalViewController 没有释放?
我有下一步行动。
- (IBAction)openThumbMap:(UIButton *) sender
{
ThumbmapViewController *viewController = [[ThumbmapViewController alloc] initWithInfo:mainPages];
viewController.title = self.title;
viewController.delegate = self;
[self presentModalViewController:viewController animated:YES];
[viewController release];
}
很简单,不是吗?好吧...一旦我这样做 [selfmissModalViewControllerAnimated:YES]
;在 viewController 内部,我返回,但是内存没有释放它。更糟糕的是,如果我再次调用它,内存又会增加。为什么?
在我的 viewController 内部,我创建了很多 UIImageView,在将这些类似的子视图添加到 viewController 的视图中后,我将其释放。因此,如果所有这些都像子视图一样,则必须在解除控制器后释放它,不是吗?
问题是。为什么内存还增加呢?
编辑:
在我的 initWithInfo: 方法中,我使用父 viewController 中的数据设置了一个 NSArray 属性。使用这个数组,我创建了一堆小的 UIImage,当我完成模态视图控制器时,我会释放它们。
I have the next action.
- (IBAction)openThumbMap:(UIButton *) sender
{
ThumbmapViewController *viewController = [[ThumbmapViewController alloc] initWithInfo:mainPages];
viewController.title = self.title;
viewController.delegate = self;
[self presentModalViewController:viewController animated:YES];
[viewController release];
}
Simple, isn't? Well... once I do [self dismissModalViewControllerAnimated:YES]
; inside of the viewController, I go back but, the memory doesn't release it. And the worse is, if I call it again, memory increase again. Why?
Inside of my viewController I create a lot of UIImageViews, which I release it after add these like subviews to the view of the viewController. So, if all of it are like subviews, must release it after dissmis the controller, isn't?
The question is. Why the memory still increase it?
Edit:
Into my initWithInfo: method I set a NSArray property with the data from the parent viewController. With this array I create a bunch of small UIImages that I release when I finish my modal view controller.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不是模态视图控制器本身,而是加载到里面的 UIImage。我发现当您调用
[UIImage imageNamed:@"blahblah.jpg"]
时,iOS 会创建一个缓存,以防您再次调用该图像。因此,使用[UIImage imageWithData:(NSData *)]
是我的错误表述问题的答案。It wasn't the modal view controller itself, but the UIImage loaded inside. I discover that when you call
[UIImage imageNamed:@"blahblah.jpg"]
, iOS creates a cache, in case you are calling that image again. So, using[UIImage imageWithData:(NSData *)]
is the answer for my bad-formulated question.