Closing tabs/reaping associated processes

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Closing tabs/reaping associated processes

Postby jholt » Fri Nov 14, 2014 5:54 pm

I've implemented a multi-tab control with embedded CEF browser windows, and I need to clean up the processes created for rendering those tabs when a tab is closed (as many tabs may be created/destroyed during the applications lifespan).

The DoClose logic is as outlined on the GeneralUsage/Browser Life Span description (although the Windows fragment is now out of date, as ParentWindowWillClose() no longer exists), and seems to be functioning correctly w.r.t. handling onbeforeunload cancelling, etc.

According to the description:
When the OS function receives the second OS close event it allows the parent window to actually close. This then results in a call to OnBeforeClose(). Make sure to release any references to the browser object in the OnBeforeClose() callback.


The containing tab closes correctly, is destructed (which releases it's reference to the CefRefPtr<CefClientHandler>), and I enter DoClose again with my "isClosing" status correctly set to true, however the OnBeforeClose is never fired. I've verified that there is only 1 RefCt remaining in the DoClose, isClosing==true case, which I am expecting to be cleared by the call to OnBeforeClose, so it appears the above description is not correct, or I have implemented something incorrectly. I have also tried forcing a call to OnBeforeClose (as well as just setting m_Browser = nullptr) in the DoClose, but that simply decreases the overall (static) m_BrowserCount.

I've seen a few other posts related to this topic, and now I'm wondering if render process cleanup is even supported in CEF (short of final exiting the parent process)? I had expected that once the associated client handler/browser references dropped to zero, the render/gpu processes would be notified and perform a clean exit.

Related posts I've seen:
* http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=11123&p=18852&hilit=ParentWindowWillClose#p18852
* http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=4120&start=20

Has anyone successfully implemented this?

My environment:
CEF3 3.1916.1701
multi-process=true
(32-bit Windows 7)
jholt
Techie
 
Posts: 27
Joined: Fri May 02, 2014 4:29 pm

Re: Closing tabs/reaping associated processes

Postby jholt » Fri Nov 14, 2014 6:30 pm

Found my mistake - after adding the DestroyWindow in the ClientHandler::DoClose as shown below (as per the first thread mentioned), the corresponding render processes terminate.

I suggest updating the General Usage Windows example to show this, as well removing the ParentWindowWillClose reference.

Code: Select all
  // Closing the main window requires special handling. See the DoClose()
  // documentation in the CEF header for a detailed destription of this
  // process.
  if (m_BrowserId == browser->GetIdentifier() && !m_bIsClosing) {
    // Notify the browser that the parent window is about to close.
    //browser->GetHost()->ParentWindowWillClose();   // <-- no longer exists

    ::DestroyWindow(browser->GetHost()->GetWindowHandle());

    // Set a flag to indicate that the window close should be allowed.
    m_bIsClosing = true;
    return true;
  }
jholt
Techie
 
Posts: 27
Joined: Fri May 02, 2014 4:29 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 40 guests