iPad 应用程序中奇怪的内存泄漏
我在 iPad 应用程序中遇到了非常奇怪的内存泄漏问题。
我有一个导航控制器应用程序,通过单击主控制器上的按钮我推送一个 ViewController,该视图控制器有一个 UIWebView。它使用 IBOutlet 连接到 NIB 文件。
@interface MyViewController : UIViewController {
IBOutlet UIWebView *webview;
}
在 Webview 中,当用户触摸它时,它开始播放 YouTube 视频。
现在,当我点击返回按钮时,我会弹出视图控制器。
问题来了,视频没有停止播放,原因是 UIWebView 实例仍然存在,为此我在 dealloc 方法中检查了它的保留计数,它显示 2,但它应该是 1。我没有保留它完全在我的代码中。
奇怪的事情来了,只是为了测试我调用了对象的释放,这一次视频停止播放。
我知道这不是正确的做法,但没有答案说明为什么会这样。
关于我哪里出错的任何评论。
谢谢
I am having a really weird memory leak in an iPad App.
I have a Navigation Controller App, By clicking a button on the Main Controller i push a ViewController, This View Controller has a UIWebView. which is connect to the NIB file using IBOutlet.
@interface MyViewController : UIViewController {
IBOutlet UIWebView *webview;
}
And in the Webview when the user touches it starts playing the youtube video.
Now when i tap return button i pop the view controller back.
Here comes the problem, the video does not stop playing and the reason is the UIWebView instance is still existing, for this i checked its retain count in the dealloc method and it shows 2, but it should have been 1. I have not retained it at all in my code.
And here come the weird stuff, just for testing i called release on the object, and this time the video stopped playing.
I know this is not the right thing to do , but no answers as to why its happening such a way.
Any comment on where i am going wrong.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要考虑两点:
MyViewController 是如何分配和释放的?当您推送视图控制器时,它将再次保留。您实际上可以在代码中的该位置释放它。
在弹出 MyViewController 之前,尝试将 webview 的 delegate 设置为 nil。
Two points to consider:
How is the MyViewController allocated and released? When you push a viewcontroller, it will be retained once again. You can actually release it at that point in the code.
Before popping MyViewController, try to set webview's delegate to nil.