WebViews不释放内存?

时间:2013-02-18 05:23:34

标签: objective-c cocoa memory-management webview automatic-ref-counting

好的,这是我的情况:

  • 我正在编写一个标签式应用程序(使用PSMTabBarControl)。
  • 每个标签包含一个WebView(实际上是一个MyDocument个实例,其中包含一个WebView子类 - 但不应该有太大区别)
  • 我正在使用ARC。

这是问题:

  • 添加新标签(=文档/网页视图)时,系统监视器中的内存快速上升
  • 删除标签时,内存取消分配

发生了什么事?关于如何解决这个问题的任何想法?


如果您需要了解其他信息(例如具体代码),请告知我们。我准备开始用这个东西撞到墙上了......

1 个答案:

答案 0 :(得分:3)

不确定如何,但这些对我有用,
删除WebView时(当然我只需要在应用程序关闭时执行一次),我正在调用[webview close function]参​​考文档,

/*!
    @method close
    @abstract Closes the receiver, unloading its web page and canceling any pending loads.
    Once the receiver has closed, it will no longer respond to requests or fire delegate methods.
    (However, the -close method itself may fire delegate methods.)
    @discussion A garbage collected application is required to call close when the receiver is no longer needed.
    The close method will be called automatically when the window or hostWindow closes and shouldCloseWithWindow returns YES.
    A non-garbage collected application can still call close, providing a convenient way to prevent receiver
    from doing any more loading and firing any future delegate methods.
*/
- (void)close;

/*!
    @method setShouldCloseWithWindow:
    @abstract Set whether the receiver closes when either it's window or hostWindow closes.
    @param close YES if the receiver should close when either it's window or hostWindow closes, otherwise NO.
*/