Skip to content

Commit 57bf983

Browse files
committed
Run gc before taking heapsnapshot
1 parent 7551adf commit 57bf983

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

apps/webapp/app/routes/admin.api.v1.snapshot.ts

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { json, type DataFunctionArgs } from "@remix-run/node";
77
import { prisma } from "~/db.server";
88
import { authenticateApiRequest } from "~/services/apiAuth.server";
99
import { requireUser } from "~/services/session.server";
10+
import { runInNewContext } from "node:vm";
1011

1112
// Format date as yyyy-MM-dd HH_mm_ss_SSS
1213
function formatDate(date: Date) {
@@ -32,6 +33,14 @@ export async function loader({ request }: DataFunctionArgs) {
3233
throw new Response("You must be an admin to perform this action", { status: 403 });
3334
}
3435

36+
v8.setFlagsFromString("--expose-gc");
37+
const gc = global.gc ?? runInNewContext("gc");
38+
39+
gc();
40+
41+
// disable expose-gc
42+
v8.setFlagsFromString("--noexpose-gc");
43+
3544
const tempDir = os.tmpdir();
3645
const filepath = path.join(
3746
tempDir,

0 commit comments

Comments
 (0)