0

this is code

QWebView* webView=new QWebView(this); 
 webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
webView->load(QUrl(newsUrl));

After Delete any case, there will be some memory can not be deleted

Silence
  • 39
  • 6

1 Answers1

0

If you set the object parent in the constructor using this

( QWebView* webView=new QWebView(this); )

Then you should not call delete directly the memory will be freed when the class you provided as a parent will be destroyed

If you want to use delete then simply construct the object like this:

QWebView* webView=new QWebView();
opc0de
  • 11,557
  • 14
  • 94
  • 187
  • @Silence how do you figure out there is a memory leak ? could you be more explicit in your problem – opc0de Oct 29 '12 at 09:05
  • I use windows os,The run QWebView more within 20M can not be deleted. – Silence Oct 29 '12 at 09:13
  • @Silence my friend 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 – opc0de Oct 29 '12 at 09:16
  • `int main(int argc, char *argv[]) { QApplication a(argc, argv); QWebView* w=new QWebView(); w->settings()->setObjectCacheCapacities(0,0,0); w->load(QUrl("http://www.sina.com.cn")); w->show(); delete w; return a.exec(); }` – Silence Oct 29 '12 at 09:47
  • @Silence the memory is freed but not in that moment ;) only the object is destroyed.Don't bother your self with these problems they are OS problems.If you freed the memory is no longer your concern and delete will free the memory at some point ;) – opc0de Oct 29 '12 at 09:48