Results 1 to 3 of 3

Thread: QtWebKit with javascript: memory leak?

  1. #1

    Default QtWebKit with javascript: memory leak?

    Hi,

    I've written a software which browses multiple websites containing javascript.
    To achieve that, I'm using QWebPage with QWebSettings::JavascriptEnabled.
    The problem is that over the time the ram usage is constantly increasing, until more than 1-2 gb of ram is used and then crashes.
    I've written a little test snippet to demonstrate the issue.

    Ram usage
    • Without running the snippet: 7,7mb
    • With QWebSettings::JavascriptEnabled set to false: 40mb
    • With QWebSettings::JavascriptEnabled set to true: 110mb


    If you put some breakpoints, you can see the ram usage increasing with each site.

    Do you have any solution so that I can reduce the amount of ram used? I guess the problem is the page/frame isn't deleted because some javascript code is executed (maybe?). If so, any way to force the javascript to stop, once the page is loaded? Or perhaps a way to force the page to delete all its content?


    Qt Code:
    1. QWebPage page;
    2. page.settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
    3.  
    4. QEventLoop loop;
    5. connect(&page, SIGNAL(loadFinished(bool)), &loop, SLOT(quit()));
    6.  
    7. for (int i=0; i<2; i++) {
    8. page.mainFrame()->load(QUrl("http://www.youtube.com"));
    9. loop.exec();
    10.  
    11. page.mainFrame()->load(QUrl("http://www.youtube.com"));
    12. loop.exec();
    13.  
    14. page.mainFrame()->load(QUrl("http://www.9gag.com"));
    15. loop.exec();
    16.  
    17. page.mainFrame()->load(QUrl("http://www.google.com"));
    18. loop.exec();
    19.  
    20. page.mainFrame()->load(QUrl("http://www.facebook.com"));
    21. loop.exec();
    22.  
    23. page.mainFrame()->load(QUrl("http://www.amazon.com"));
    24. loop.exec();
    25.  
    26. page.mainFrame()->load(QUrl("http://www.twitter.com"));
    27. loop.exec();
    28.  
    29. page.mainFrame()->load(QUrl("http://qt-project.org"));
    30. loop.exec();
    31.  
    32. page.mainFrame()->load(QUrl("http://imdb.com"));
    33. loop.exec();
    34.  
    35. page.mainFrame()->load(QUrl("http://techcrunch.com/"));
    36. loop.exec();
    37. }
    To copy to clipboard, switch view to plain text mode 

    I'm using Qt 5.1 RC
    Last edited by monkazer; 19th June 2013 at 22:02.

  2. #2

    Default Re: QtWebKit with javascript: memory leak?

    Anyone? Please I really need to fix this issue...Is it a bug in Qt? The memory should be cleared once the QWebPage is destroyed.

  3. #3

    Default Re: QtWebKit with javascript: memory leak?

    Ok, I've found the issue. Sorry the code above wasn't totally accurate.
    In my app I have QWebSettings::AutoLoadImages disabled. It looks like if QWebSettings::JavascriptEnabled is enabled, we also need to enable QWebSettings::AutoLoadImages, otherwise the memory usage is a lot higher.
    I did the above test again without loading the images and the ram usage was 220mb!

Similar Threads

  1. QTWebKit, out of control Javascript CPU usage
    By Dkamerad in forum Qt Programming
    Replies: 2
    Last Post: 12th December 2014, 05:01
  2. Call a JavaScript function from C++ using QtWebkit
    By Rastersoft in forum Qt Programming
    Replies: 9
    Last Post: 14th May 2014, 12:03
  3. Replies: 0
    Last Post: 19th September 2012, 12:32
  4. [QtWebKit] Inject JavaScript properly when DOM loads..
    By fab_74 in forum Qt Programming
    Replies: 2
    Last Post: 27th March 2011, 17:58
  5. QtWebkit and JavaScript error messages
    By Diph in forum Qt Programming
    Replies: 1
    Last Post: 29th April 2009, 11:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.