Qt World Summit: Submit your Presentation

Limiting memory consumption in Java script

  • All,

    I've got an applciation which displays many web pages using opengl after rendering to an image using a qpainter. I find that when I enable javascript after a while the windows 7 process will crash from running out of heap space. When I disable javascript, this is not an issue.

    What is even more confusing is that when debugging the heap (using valgrind on linux, Memory Validator on Win32, and umdh on Win32) the heap reported looks normal and growth is as expected; no leaking objects. However, the task manager in win32 reports that memory is growing consistently. Is there any trickery used in QtWebKit on win32 for allocating memory?

    Finally, is there any way to:

    Limit the memory consumed by JavaScript (including compiled javascript code). Or,

    Flush all memory consumed by JavaScript on destruction of a QWebPage.

    Thanks in advance,


  • I would also very much like to be able to control and/or flush the memory used by JavaScript. I have a similar application which loads many web pages, and on certain pages the memory use skyrockets out of control. I worked around this by having the app restart when memory usage reaches a certain point.

    This is a poor answer to the problem though, as restarting is not always feasible in all cases.

    Assistance would be greatly appreciated in this matter.

  • The approach I'm now working on is using process spawning to avoid this problem.

    Basically, I construct a separate process which creates a shared memory segment (QSharedMemory), and writes output to stdout. The shared memory segment is a data channel (containing the RGBA buffer for a QPainter), and stdout is the command channel (e.g. pick up freshly rendered content on this qrect).

    The main process connects to this shared memory segment using QSharedMemory, and instantiates the process with QProcess.

    Because I need Win32 compatibility, I need to suck the big one and create a new process every time a web page is spun-up - using a new QProcess instance. On unix, however, I believe that one could create one main process and call fork() every time a new web view is required. This would allow the parent process to do much of the setup work prior to forking, thus an efficiency gain. If you are on unix you may be able to use this approach.

    Unfortunately, I can't see how Javascript can be viewed as a serious language - and I can't understand why this language is being chosen for the basis of QML. I only see a lot of pain for developers trying to get their systems reliable with that approach. Alternatively, they'll be back to forking processes for reliability and threading - back to early 1990's :)


Log in to reply