Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to Terminate QtWebEngine Before Exiting

How to Terminate QtWebEngine Before Exiting

Scheduled Pinned Locked Moved Solved General and Desktop
webengineopenglmemory leak
3 Posts 2 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ErikaE Offline
    ErikaE Offline
    Erika
    wrote on last edited by Erika
    #1

    Context: It is very important for our system to be memory-leak free. We build Qt, linking to mfc to ensure a common heap is used. This allows us to work with the _CRTDBG_MAP_ALLOC/_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ) calls to detect memory leaking on exit.

    We've recently added a QtWebEngineView as a widget to our system, which brings along all the web engine processes and threads. On exit, it appears that these threads aren't shut down, and all memory resources are (erroneously?) reported as leaks. I've read through the documentation, and I'm struggling to find something to "correctly" terminate and release all web engine content prior to exit. A similar issue happens when working just with an OpenGL widget.

    Question: How does one correctly terminate and release all resources - including its OpenGL context - associated with qt web engine?

    If the motivation is insufficient, another justification would be how to release all web engine resources during program execution, in the case of limited resources?

    A simple example program:

    #include <QtCore>
    #include <QtWidgets\QMainWindow>
    #include <QtWebEngine\QtWebEngine>
    #include <QtWebEngineWidgets>
    
    #define _CRTDBG_MAP_ALLOC
    
    int main( int argc, char * argv[] )
    {
    	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); // enable memory leak checking
    
    	int result = 0;
    	{
    		QApplication app( argc, argv );
    		QtWebEngine::initialize(); // reports leaks - likely not closed correctly on exit
    		QMainWindow mainWindow;
    
    		QWebEngineView *webView = new QWebEngineView; // more leaks...
    		webView->load( QUrl( "https://www.qt.io" ) ); // even more leaks...
    
    		mainWindow.setCentralWidget( webView );
    		mainWindow.resize( 800, 600 );
    		mainWindow.show();
    
    
    		result = app.exec();
    	}
    	// expected Qt to have finished offloading here
    	
    	return result;
    }
    
    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      Hi! Your code looks fine to me and my guess would be that this is a known issue. I don't think anyone here can help you with this, so better ask the devs on the mailing list.

      1 Reply Last reply
      1
      • ErikaE Offline
        ErikaE Offline
        Erika
        wrote on last edited by Erika
        #3

        Thanks Wieland for taking a look. And thanks for the mailing list suggestion! Good to know of more Qt resources.

        I've filed a bug: https://bugreports.qt.io/browse/QTBUG-56774

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved