Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Collecting WeakMap keys requires multiple GC passes

Đang mở
#581 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

@jluxenberg đang làm issue này rồi.

Từ ngày 27/10/2026.

  • #582 của @jluxenberg — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c

Hướng nghiên cứu

Start with the attached weakmap_gc_repro.c and run it using the build commands in the issue to confirm both cases. Then trace QuickJS's WeakMap and weak-reference handling in the GC; the issue does not name source files or tests, so locate the relevant code and existing GC tests. Done means the self-referencing key is collected and the chain of keys is freed after a fixed number of GC passes.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Issue

I think I've found two bugs related to weak references / WeakMap handling by the GC.

(1) An entry whose value references its own key is never collected while the WeakMap is alive.
/* Case 1: the value references its own key. */
(function () {
  var key = {};
  map.set(key, { backRef: key });
  globalThis.selfRef = new WeakRef(key);
})();

Expected result:

  • key is collected after one pass of the GC

Actual result:

  • key is never collected by the GC but should be collected on the first pass.
(2) A chain of entries (each value references the next entry's key) takes n JS_RunGC() calls to free
/* Case 2: a chain of 20 entries; each value references the next key. */
(function () {
  var key = {};
  for (var i = 0; i < 20; i++) {
    var next = {};
    map.set(key, { child: next });
    key = next;
  }
  globalThis.chainTail = new WeakRef(key);
})();

Expected result:

  • All 20 keys is collected after a fixed number (ideally one) passes of the GC.

Actual result:

  • Collecting n keys appears to require n passes of the GC.
Repro

Here's a program that reproduces the issue. Compile it like this:

quickjs $ make libquickjs.a
quickjs $ cc -O2 -I. weakmap_gc_repro.c libquickjs.a -lm -lpthread -o weakmap_gc_repro
quickjs $ ./weakmap_gc_repro

weakmap_gc_repro.c

Ngôn ngữ chính
C
Star
11.1k
Fork
1.2k
Merge trung bình
11 giờ 20 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bellard/quickjs

Tất cả issue của bellard/quickjs

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.