I've heard several mentions that Ada supports garbage collection --- and looking at the language design, it's obviously been designed with that in mind.
I have a non-real-time application for which garbage collection would be really, really useful. However I haven't seen any mention of there being a garbage collector available for my compiler, GNAT. This surprises me; even C supports garbage collection, by simply linking against libgc.
If I simply add libgc to my linker line, will it work or will horrible things happen?
I have found a libgc binding as part of the AdaCL library here: http://adacl.sourceforge.net/
However, the libgc documentation also says that libgc can't see pointers stored in blocks allocated via system
malloc(). This means that an access which is only stored in an object allocated from the default memory pool won't be considered a root and may be invalidated at any point. This disqualifies the use of standard Ada containers from storing accesses to collectable objects! This might also apply to the secondary stack --- but I don't know what the secondary stack is used for.However, my investigations do show that garbage collection does naively work:
...runs forever. So it's probably theoretical possible to do, but right now I don't think it's safe.