views:

83

answers:

2

Let's say you are implementing an interpreter for a GCed language in a language that is GCed. It seems to me you'd get garbage collection for free as long as you are reasonably careful about your design.

Is this generally how it's done? Are there good reasons not to do this?

+2  A: 

Language and runtime are two different things. They are not really related IMHO.

Therefore, if your existing runtime offers a GC already, there must be a good reason to extend the runtime with another GC. In the good old days when memory allocations in the OS were slow and expensive, apps brought their own heap managers which where more efficient in dealing with small chunks of data. That was one readon for adding another memory management to an existing runtime (or OS). But if you're talking Java, .NET or so - those should be good and efficient enough for most tasks at hand.

However, you may want to create a proper interface/API for memory and object management tasks (and others), so that your language ("guest") runtime could be implemented on to of another host runtime later on.

Lucero
A: 

For an interpreter, there should be no problem with using the host GC, IMHO, particularly at first. As always they goal should be to get something working, then make it work right, then make it fast. This is particularly true for Domain Specific Languages (DSL) where the goal is a small language. For these, implementing a full GC would be overkill.

Joel