How to implement a garbage collector?

前端 未结 8 541
灰色年华
灰色年华 2021-01-29 17:52

Could anyone point me to a good source on how to implement garbage collection? I am making a lisp-like interpreted language. It currently uses reference counting, but of course

相关标签:
8条回答
  • 2021-01-29 18:44

    Garbage collection implementation in Lisp

    Building LISP | http://www.lwh.jp/lisp/

    Arcadia | https://github.com/kimtg/arcadia

    0 讨论(0)
  • 2021-01-29 18:47

    As suggested by delnan, I started with a very naïve stop-the-world tri-color mark and sweep algorithm. I managed to keep the objects in the sets by making them linked-list nodes, but it does add a lot of data to each object (the virtual pointer, two pointers to nodes, one enum to hold the color). It works perfectly, no memory lost on valgrind :) From here I might try to add a free list for recycling, or some sort of thing that detects when it is convenient to stop the world, or an incremental approach, or a special allocator to avoid fragmentation, or something else. If you can point me where to find info or advice (I don't know whether you can comment on an answered question) on how to do these things or what to do, I'd be very thankful. I'll be checking Lua's GC in the meantime.

    0 讨论(0)
提交回复
热议问题