开发者

How should i deduce when the GC should run?

I am writing a statically compiled language and i would like to support garbage collection. before designing it i wo开发者_Go百科uld like to know how i should i deduce when the GC should run?

Should it be after every 16mb allocate interval? (checking after enough rises or just before it allocates 16+mb). Is there a case to check ealier so loops can reuse the same memory to be efficient? etc


The best time for an GC to run is propably "when the program has some time left". For example, if you have a run loop and no event is queued it might be a good time to run the GC. And then maybe also if the GC allocator notices that it would need to ask the OS for more memory. I think it also depends on the GC design, e.g. It's possible to design a GC that runs in its own thread and doesn't interrupt the program vs. the usual "stop the world" GCs.

Question is also, do you want to implement a GC just for learning ? Or do you just want a GC ? In the later case I suggest you look into the Boehm GC.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜