From 9cf86eed08e00a81fcf8dce0c3977a33681a953b Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 19 Sep 2025 03:52:59 -0700 Subject: [PATCH] Free more memory in destructOnExit and add assertion --- src/bun.js/bindings/ZigGlobalObject.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index df656b263b..e1ef3c54c4 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -210,6 +210,8 @@ #include #endif +#include "mimalloc.h" + using namespace Bun; BUN_DECLARE_HOST_FUNCTION(Bun__NodeUtil__jsParseArgs); @@ -4665,7 +4667,10 @@ extern "C" void Zig__GlobalObject__destructOnExit(Zig::GlobalObject* globalObjec globalObject = nullptr; vm.heap.collectNow(JSC::Sync, JSC::CollectionScope::Full); vm.derefSuppressingSaferCPPChecking(); + ASSERT_WITH_MESSAGE(vm.hasOneRef(), "JSC::VM has more than one ref. destructOnExit will not work."); vm.derefSuppressingSaferCPPChecking(); + WTF::releaseFastMallocFreeMemory(); + mi_collect(false); } #include "ZigGeneratedClasses+lazyStructureImpl.h"