Results 1 to 16 of 16

Thread: QWebPage memory leakege.

  1. #1
    Join Date
    Jun 2012
    Posts
    4

    Default QWebPage memory leakege.

    Hello! I have found that QWebPage leaks memrory.
    Here is my code:
    Qt Code:
    1. #include <QApplication>
    2. #include <QWebPage>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. while(1){
    8. QWebPage* page = new QWebPage();
    9. delete page;
    10. }
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    It leaks a lot of memory.
    Can anyone please exmplain what I do wrong? Or may be this is a bug of WebKit?
    I'm using Qt Creator 2.4.1 under Windows 7.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebPage memory leakege.

    How do you know you have a leak here? How did you check that?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2012
    Posts
    4

    Default Re: QWebPage memory leakege.

    Quote Originally Posted by wysota View Post
    How do you know you have a leak here? How did you check that?
    I'm just starting process manager and watch for memory usage of this process. I can see that usage of memory grows up 300-500kb per second.
    I'm using debug version of project, version of QT libs is 4.8.1.0 and QTWebKit 4.9.0.0

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebPage memory leakege.

    Process manager does not report memory leaks.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2012
    Posts
    4

    Default Re: QWebPage memory leakege.

    Quote Originally Posted by wysota View Post
    Process manager does not report memory leaks.
    Well, in this case it looks like you can't help me. Will hope specialists from qt.nokia.com can.
    Thank you for your reply and good luck with TrollTech.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebPage memory leakege.

    "Specialists from qt.nokia.com" will tell you the same thing. Process manager does not report memory usage correctly since it depends on how the system memory allocator works and the allocator usually doesn't deallocate memory from a process upon calling free/delete since memory allocation is an expensive process so it's deferred hoping that the process will want to reclaim the memory. If you suspect you have a memory leak then use a tool dedicated to looking for memory leaks.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QWebPage memory leakege.

    Oh dear. What a strange response.

    If you are going to make the extraordinary claim that something used widely leaks memory on a grand scale then you will need extraordinary evidence. Windows task manager does not detect memory leaks: and the high water mark it does report will be distorted by the inability of housekeeping task to compete with a process in a tight loop. You will need to use a tool that does detect memory leaks to gather your extraordinary evidence... even for the "specialists from qt.nokia.com" (not that Nokia is the author of QtWebKit).

    Valgrind is an option on UNIX-like systems and there are all sorts of options for Windows

  8. #8
    Join Date
    Jun 2012
    Posts
    4

    Default Re: QWebPage memory leakege.

    Well, looks like work around for deleting pages ( and all other QObjects) is to run exec and do it in some slot by event..

  9. #9
    Join Date
    Mar 2012
    Posts
    14
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QWebPage memory leakege.

    I'm having similar issues - what exactly did you do to overcome this?

  10. #10
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWebPage memory leakege.

    similar issues being non-existent memory leak(s)?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  11. #11
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QWebPage memory leakege.

    I think that the OP has a basic misunderstanding of how heap memory management works. The "delete" operator does not do anything more than execute the destructor for the object instance being deleted, make the pointer to the memory used by that instance invalid, and tell the run-time memory manager that the memory in question can be reused if needed. But the tight loop is asking for new memory so fast, the memory manager can't do anything to optimize.

    Putting millions of new() and delete() calls in a tight loop is like filling a bucket with water, emptying it, filling it again, emptying it, and doing it all so quickly that even if the drain plug is not in the bathtub, the bathtub eventually overflows because it can't hold any more water or drain it away fast enough.

    If the OP wants proof that there is no memory leak, put a limit on the while() loop and let the program eventually exit (without having to kill it through the debugger). Let it run the loop 100 or 10000 times, then see if the debugger reports any memory leaks when the program exits normally.

  12. #12
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWebPage memory leakege.

    Thread was hijacked - I dont think the OP is around any more.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  13. #13
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QWebPage memory leakege.

    Yes, you're probably right - didn't notice the big gap in dates. This forum should have the option to automatically close a thread to further replies after some period of time. Having an archival record is a good thing; being able to resurrect a years-old post by hijacking it with a new reply isn't.

    The OP has probably gone off to consult with the experts at qt.nokia.com. No sense trying to get a decent answer from the monkeys here.

  14. #14
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWebPage memory leakege.

    ooh ooh ah ah
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  15. #15
    Join Date
    Mar 2012
    Posts
    14
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QWebPage memory leakege.

    Ok settle down.

    My scenario was quite a bit more complicated - I'm using QWebPage wrapped by a QObject utilised in QtScript, and I was getting all sorts of leaks and crashes when doing looped creations via QtScript prototype wrappers (e..g BBADBEEF)
    Eventually after putting in QScriptEngine::collectGarbage calls and doing QApplication:rocessEvents and QScriptEngine::setProcessEventsInterval memory is now released and I can run scripts with large loops and memory usage is pretty much static.

    But get rid of the 1st two and it was leaking like a sieve and crashing randomly, I think that was also a timing thing with object destruction and the event loop being processed etc. I don't have the time to understand it all right now, it was painful enough already.

    I might revert the changes at some point and post the results and code snippets to replicate the problem here if anyone is interested in commenting.

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebPage memory leakege.

    Please don't abuse the term "memory leak". If memory leaks, it means it can't be reclaimed by the system memory allocator. If you just don't allow the framework you're using to release the memory because of a tight loop, then there is no leak, you just have an incorrect design in your application that causes unstable memory use.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QWebPage::extension
    By Vladimir123 in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2011, 21:20
  2. Unwanted downloads with QWebPage/QWebPage
    By ouekah in forum Newbie
    Replies: 6
    Last Post: 11th May 2010, 22:48
  3. How to use qwebpage in non-gui app
    By Cykus in forum Newbie
    Replies: 4
    Last Post: 10th May 2010, 11:35
  4. Can QWebPage see changes in a website
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 15th August 2009, 23:23
  5. QwebPage within a QGraphicsWidget
    By Osprey in forum Qt Programming
    Replies: 0
    Last Post: 16th June 2009, 17:32

Tags for this Thread

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.