1

I want to implement a new garbage collector (mark & sweep), but there are too many dup/free bits and pieces all over the code。I think I should turn off first then think about other things. This is my first time working in this field and unfortunately it's important. What should I do?

I don't have a clear understanding of this, because I didn't read all the source code about the dup/free part.

chqrlie
  • 131,814
  • 10
  • 121
  • 189
rosty
  • 11
  • 1
  • 1
    What is your plan, come to Stackoverflow for every step on your way? – Holger Feb 20 '23 at 13:37
  • @Holger Sry for my wording. In my opinion, gc.disable() and gc.scan() are the same difficulty.maybe i should comment out and see what happens? or before that i should read a book to study..eg i never write my own garbage collector,to say nothing of rebuilding. at last thanks for your comment and hope for teaching more – rosty Feb 20 '23 at 18:26
  • 2
    Yes, “read a book” (or two) is the right approach. You can also find articles on the Internet about this topic. – Holger Feb 21 '23 at 13:04

1 Answers1

0

QuickJS uses a hybrid garbage collector: it uses reference counts and a clever cycle detection mechanism to retrieve memory for unreachable self referencing objects.

While changing the garbage collecting mechanism is feasible and probably simple if your goal is to just remove it, switching to a mark and sweep method is more difficult to achieve because it requires deep changes in the implementation, such as linking all allocated objects such as strings and bignums, which is currently not needed.

It also requires subtle changes in many functions that construct objects to prevent them from being collected by the GC that could be invoked on any object allocation.

Making the garbage collector optional is a feature we should add. Using a mark and sweep approach is not on our wish list, but if you succeed at implementing it, we shall certainly be interested.

chqrlie
  • 131,814
  • 10
  • 121
  • 189