aboutsummaryrefslogtreecommitdiff
path: root/test/leaks/http-static-leak.ts
blob: 09935d24d297a0932caa99b776b65a3fa98f6399 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { heapStats } from "bun:jsc";
var prevCounts;
export default {
  fetch(req) {
    const out = {};
    const counts = heapStats().objectTypeCounts;
    for (const key in counts) {
      if (prevCounts) {
        if (prevCounts[key] && counts[key] > prevCounts[key]) {
          out[key] = counts[key];
        }
      } else {
        if (counts[key] > 1) {
          out[key] = counts[key];
        }
      }
    }
    prevCounts = counts;
    if (req.url.includes("gc")) {
      Bun.gc(false);
    }

    return new Response(JSON.stringify(out), {
      headers: {
        "content-type": "application/json",
      },
    });
  },
};