firemail

标题: 关于QWebView内存 [打印本页]

作者: jimu    时间: 2016-11-28 18:31
标题: 关于QWebView内存
本帖最后由 jimu 于 2016-11-28 18:33 编辑

http://bbs.csdn.net/topics/390261419
  1. QWebView* webView=new QWebView(this); //创建QWebView
  2.      webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
  3.     webView->load(QUrl(newsUrl));
复制代码
之后、不管你是delete还是怎么地、指针可以删除、

但是总有那么14M左右的内存怎么都释放不了


求思路 、 求思路 、求思路



stackoverflow 是这样回答的
when you call delete the memory isn't freed in that moment it takes a while and if other objects are not created it might not geed freed until the end of the application. QWebView is a complex class 20 M in 2012 are no longer a concern.The memory will be freed if you do this properly


作者: jimu    时间: 2016-11-28 18:33
  1. #include <QtGui/QApplication>
  2.   #include <QWebView>
  3. int main(int argc, char *argv[])
  4. {
  5.     QApplication a(argc, argv);

  6.     QWebView* w=new QWebView();
  7.     w->settings()->setObjectCacheCapacities(0,0,0);
  8.     w->load(QUrl("http://www.sina.com.cn"));
  9.    w->show();
  10.    delete w;
  11.      return a.exec();
  12. }
复制代码
木有QWebView运行内存是5M、加上QWebView内存是17M


  1. for(int i=0;i<1000;i++){
  2. QWebView* w=new QWebView();
  3.     w->settings()->setObjectCacheCapacities(0,0,0);
  4.     w->load(QUrl("http://www.sina.com.cn"));
  5.    w->show();
  6.    delete w;
  7. }

复制代码
这样运行之后、内存还是一样的!
我个人认为,QWebview加载了内容,就是已经放入内存了。就算你delete了,那部分内存还是被分配给你了。这时只能等系统回收了。而且这种情况,有点类似于以前的非Qt程序也会有这样的情况。你试试最小化后再看看内存占用数?


应该就是只有等自动回收、或者程序退出!


如果我程序一直不退出来,还是不是内存一直会增大?无法释放,到最后是不是系统崩溃???

作者: jimu    时间: 2016-11-29 16:46
本帖最后由 jimu 于 2016-11-29 16:52 编辑

http://www.qtcentre.org/threads/ ... on-QWebView-I-think

You are reusing the webview object but not the webpage object. The page will probably get deleted once you delete the view but as you reuse the view, it's probably not getting deleted waiting until its parent is. You can call QWebView::back() and the previous page will get shown so it's probably not deleted because of that exact behaviour. If you want to get rid of it, then do it manually by calling delete (or deleteLater()) on the webpage object.
And I set no history, then no "back" and "forward" option are available.




It would appear that this is a bug in QWebView:

https://bugs.webkit.org/show_bug.cgi?id=24458

作者: jimu    时间: 2016-11-29 17:09
http://stackoverflow.com/questio ... view-on-qt4-and-qt5
作者: jimu    时间: 2016-11-29 17:09
http://www.qtcentre.org/threads/ ... ink?goto=nextnewest
作者: jimu    时间: 2016-11-29 17:30
  1. QWebView *web;
  2. web->setUrl(QUrl("http://www.google.com"));


  3. QWebView *web;
  4. web->page()->mainFrame()->setUrl(QUrl("http://www.google.com"));
复制代码

作者: jimu    时间: 2016-11-29 17:35
Read This For A "Pseudo-Solution" To The Qt Webkit Memory Leak:

http://qt-project.org/forums/viewthread/11105
作者: jimu    时间: 2016-11-29 17:52
QWebElement body=myWebView->page()->mainFrame()->findFirstElement("body");body.setAttribute("onunload","myFunction()");
QWebSettings::clearMemoryCaches();webView->history()->clear();





欢迎光临 firemail (http://firemail.wang:8088/) Powered by Discuz! X3