You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There should be a documented way to close a WebContents and allow it to be garbage collected.
I'd prefer not to document the existing webContents.destroy() method if possible as it's quite aggressive and makes the underlying WebContents object unusable after being called. Ideally, I'd like to have a webContents.close() method that returns the object to the state that it was in prior to loadURL() being called, and marks it as available for GC once references are dropped.
i.e. this should work:
constbv=newBrowserViewbv.webContents.loadURL("https://example.com")// ... later ...bv.webContents.close()// If the reference to `bv` were dropped here, both `bv` and the webContents would be available for collection// ... but if the reference is retained, the WebContents should be re-usable at a later date:bv.webContents.loadURL("https://example.com")
Reacted by pushkin-, Johan Knutzen, Kevin, Mauve Signweaver, MonkeyFigaro, Aleksi Asikainen, Keeley Hammond, Biru Mohanathas, Stewart Lord, Ava Creeth and 7 more
I noticed that this issue has been labeled as an enchancement, is there any way we can label it with something that convey a bit more urgency? e.g. a bug/regression perhaps.
Reasoning as partially quoted from the #23578 (comment) by @yohan1234 in PR discussion which removes BrowserView::destroy.
[...] The problem is:
BrowserView.destroy was removed
webContents does not have a public API destroy function
[...]
So a previously working browser view (in electron v10 and below) now cause a memory leak (in electron v11 and above) which makes it unusable. 1 work around proposed in the discussion was to use an undocumented webContents.destroy() which is not ideal so would love to avoid it if possible.
👋 @pushkin- thanks for linking, OOC, are you currently on electron v11 in your app?
if so, have you been using webContents.destroy?
I am interested in whether the method is safe enough to use without causing any crashes 🤔
@kevinlinv Yes I'm on Electron 11. I encountered a crash which was because I wasn't detaching the BrowserView from the BrowserWindow before destroying its WebContents, but now that I'm doing that, I haven't seen any crashes.
A friendly 🏓 sorry for the noise. Would appreciate if this issue is looked at by someone who knows the codebase 👍
It's rather unfortunate for browser view to leak in latest version of electron by default.
+1 for this issue. The work-around (calling destroy() on webContents) addressed the leak for me, but I did experience a hard crash that required wrapping the destroy call in setImmediate to avoid.
a previously working browser view (in electron v10 and below) now cause a memory leak (in electron v11 and above) which makes it unusable.
Just so I'm clear on what the issue is here, the app were previously calling browserview.destroy(), then that function was removed—so the app was changed to not call destroy(), and now leaks?
I think this should be straightforwardly fixable by calling browserview.webContents.destroy() where there was previously a call to browserview.destroy(). I'm aware that the WebContents.destroy() method is not documented, but in this case I think it's OK to use. Once there exists a documented way to shut down a WebContents, the destroy() call can be replaced with that.
@stewartlord would you be able to file a separate bug with the crash info?
Just so I'm clear on what the issue is here, the app were previously calling browserview.destroy(), then that function was removed—so the app was changed to not call destroy(), and now leaks?
Yes, it's exactly as you've pointed out.
I think this should be straightforwardly fixable by calling browserview.webContents.destroy() where there was previously a call to browserview.destroy(). I'm aware that the WebContents.destroy() method is not documented, but in this case I think it's OK to use. Once there exists a documented way to shut down a WebContents, the destroy() call can be replaced with that.
True, from my own use case, I'd prefer to not use undocumented api, but not too fussed if I really have to and will do so to allow upgrading to electron@11
It is more into the point of view of new BrowserView users in latest electron that would make this issue slightly unfortunate, as they would immediately run into a memory leak and may not be aware of it before they stumble into this issue somehow.
+1 for this issue. The work-around (calling destroy() on webContents) addressed the leak for me, but I did experience a hard crash that required wrapping the destroy call in setImmediate to avoid.
Activity
kevinlinv commentedon Jan 4, 2021
Heya @nornagon @ckerr, Happy new year 🎉
I noticed that this issue has been labeled as an enchancement, is there any way we can label it with something that convey a bit more urgency? e.g. a bug/regression perhaps.
Reasoning as partially quoted from the #23578 (comment) by @yohan1234 in PR discussion which removes
BrowserView::destroy.So a previously working browser view (in electron v10 and below) now cause a memory leak (in electron v11 and above) which makes it unusable. 1 work around proposed in the discussion was to use an undocumented
webContents.destroy()which is not ideal so would love to avoid it if possible.pushkin- commentedon Jan 5, 2021
related issue
kevinlinv commentedon Jan 5, 2021
👋 @pushkin- thanks for linking, OOC, are you currently on electron v11 in your app?
if so, have you been using
webContents.destroy?I am interested in whether the method is safe enough to use without causing any crashes 🤔
pushkin- commentedon Jan 5, 2021
@kevinlinv Yes I'm on Electron 11. I encountered a crash which was because I wasn't detaching the BrowserView from the BrowserWindow before destroying its WebContents, but now that I'm doing that, I haven't seen any crashes.
kevinlinv commentedon Jan 5, 2021
Nice, thanks for the info, I might consider using
webContents.destroyand update toelectron v11given the need to support Apple ARM 👌kevinlinv commentedon Jan 15, 2021
A friendly 🏓 sorry for the noise. Would appreciate if this issue is looked at by someone who knows the codebase 👍
It's rather unfortunate for browser view to leak in latest version of electron by default.
stewartlord commentedon Jan 20, 2021
+1 for this issue. The work-around (calling destroy() on webContents) addressed the leak for me, but I did experience a hard crash that required wrapping the destroy call in
setImmediateto avoid.nornagon commentedon Feb 2, 2021
Just so I'm clear on what the issue is here, the app were previously calling
browserview.destroy(), then that function was removed—so the app was changed to not calldestroy(), and now leaks?I think this should be straightforwardly fixable by calling
browserview.webContents.destroy()where there was previously a call tobrowserview.destroy(). I'm aware that theWebContents.destroy()method is not documented, but in this case I think it's OK to use. Once there exists a documented way to shut down a WebContents, thedestroy()call can be replaced with that.@stewartlord would you be able to file a separate bug with the crash info?
kevinlinv commentedon Feb 3, 2021
Hey @nornagon thanks for the reply.
Yes, it's exactly as you've pointed out.
True, from my own use case, I'd prefer to not use undocumented api, but not too fussed if I really have to and will do so to allow upgrading to
electron@11It is more into the point of view of new
BrowserViewusers in latest electron that would make this issue slightly unfortunate, as they would immediately run into a memory leak and may not be aware of it before they stumble into this issue somehow.vladimiry commentedon Jun 10, 2021
@stewartlord I've just placed the respective issue with attached core dump.
stewartlord commentedon Jun 10, 2021
@vladimiry Thank you 🙏 ..and @nornagon looks like I failed to deliver repro steps - very sorry about that!
vladimiry commentedon Jun 15, 2021