mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-10-08 20:32:00 -04:00
Merge pull request #3607 from lightpanda-io/cleanup-abandoned-document-parsers
mem: Track / Free abandoned html5ever parsers
This commit is contained in:
2 files changed
+22
No files matched your search
@@ -134,6 +134,10 @@ _event_target_attr_listeners: GlobalEventHandlersLookup = .empty,
|
||||
// File objects (reference counted via their Blob proto); released at teardown.
|
||||
_file_lists: std.ArrayList(*FileList) = .empty,
|
||||
|
||||
// List of Documents which called document.open() and potentially need to have
|
||||
// the parser freed.
|
||||
_script_created_parser_docs: std.ArrayList(*Document) = .empty,
|
||||
|
||||
// Every matchMedia() result of this document, so a viewport change can fire
|
||||
// their `change`.
|
||||
_media_query_lists: std.ArrayList(*MediaQueryList) = .empty,
|
||||
@@ -459,6 +463,16 @@ pub fn deinit(self: *Frame) void {
|
||||
|
||||
self._parse_state.deinit(self);
|
||||
|
||||
for (self._script_created_parser_docs.items) |doc| {
|
||||
const parser = &(doc._script_created_parser orelse continue);
|
||||
if (parser.parser.frame != self) {
|
||||
// The document was closed and re-opened on another frame
|
||||
continue;
|
||||
}
|
||||
parser.deinit();
|
||||
doc._script_created_parser = null;
|
||||
}
|
||||
|
||||
// Unregister CookieStore from session notifications before the JS
|
||||
// context (and thus the scheduler) is destroyed, otherwise a late
|
||||
// mutation could schedule a callback that never runs.
|
||||
|
||||
@@ -1184,7 +1184,15 @@ pub fn open(self: *Document, call_frame: *Frame) !*Document {
|
||||
// gone for good, as in Chrome.
|
||||
frame.cancelQueuedNavigation();
|
||||
|
||||
if (std.mem.indexOfScalar(*Document, frame._script_created_parser_docs.items, self) == null) {
|
||||
// have the page track this document (if it isn't already)
|
||||
// so that, on shutdown, it can close the parser if needed.
|
||||
try frame._script_created_parser_docs.append(frame.arena, self);
|
||||
}
|
||||
self._script_created_parser = Parser.Streaming.init(frame.arena, doc_node, frame, .{ .allow_declarative_shadow = true });
|
||||
// on start() failure the internal `handle` isn't yet create. So we can't
|
||||
// call done() and we don't want any subsequent cleanup to call done().
|
||||
errdefer self._script_created_parser = null;
|
||||
try self._script_created_parser.?.start();
|
||||
frame._parse_mode = .document;
|
||||
|
||||
|
||||
Reference in new issue
Block a user