check for leak after context is removed, as that can cause finalizers to run

This commit is contained in:
Karl Seguin
2026-01-28 14:25:37 +08:00
parent 946f02b7a2
commit 5d56fea2d3

View File

@@ -249,18 +249,19 @@ pub fn deinit(self: *Page) void {
} }
fn reset(self: *Page, comptime initializing: bool) !void { fn reset(self: *Page, comptime initializing: bool) !void {
if (comptime initializing == false) {
self._session.executor.removeContext();
// removing a context can trigger finalizers, so we can only check for
// a leak after the above.
if (comptime IS_DEBUG) { if (comptime IS_DEBUG) {
var it = self._arena_pool_leak_track.valueIterator(); var it = self._arena_pool_leak_track.valueIterator();
while (it.next()) |value_ptr| { while (it.next()) |value_ptr| {
if (value_ptr.count > 0) { log.err(.bug, "ArenaPool Leak", .{ .owner = value_ptr.* });
log.err(.bug, "ArenaPool Leak", .{ .owner = value_ptr.owner });
}
} }
self._arena_pool_leak_track.clearRetainingCapacity(); self._arena_pool_leak_track.clearRetainingCapacity();
} }
if (comptime initializing == false) {
self._session.executor.removeContext();
// We force a garbage collection between page navigations to keep v8 // We force a garbage collection between page navigations to keep v8
// memory usage as low as possible. // memory usage as low as possible.