It appears that D has multiple ways of determining which created objects are subject to GC.

For class instances, new creates a new class instance, returning a pointer to it. While "alive", other pointers may also point to the class instance. Once no pointers are pointing to this class instance, it may be garbage collected.

OOP languages such as Eiffel can keep track of pointers to class instances. They then do a generational lookup or do a thorough mark and sweep.

C, C++ and D can play shenanigans with pointers, such as casting them to size_t, which hides them from the GC.

In addition, D provides several ways to allocate and free memory.

GC.calloc can allocate memory for a slice of MyClass instances.
The developer may run GC.free to free the allocated memory.
But GC may perform its own garbage collection of GC allocated memory blocks.

Let's look at each attribute: (confirm if my analysis is right, otherwise correct)

FINALIZE - just before GC reclaims the memory, such as with GC.free,
           call destructors, aka finalizers.

NO_SCAN - There may be false positives regarding byte values that look like 'new' allocated pointers. This can result in 'garbage' memory not being collected. If we are CERTAIN that this memory block doesn't contain any pointers to
          'new' SomeClass allocated memory, then mark as NO_SCAN.

Question 1: if GC-calloc has allocated MyClass that has a string 'name' member, which may expand in size, would be still properly apply NO_SCAN.

Question 2: if GC-calloc has allocated MyClass, which may allocate new MyStudent(...), would that mean 'don't apply NO_SCAN'?

NO_MOVE - For GC.realloc, if increasing memory allocated, and it's not available,
          throw 'MEMORY_NOT_AVAILABLE' exception.

APPENDABLE - For D internal runtime use. Don't mark this yourself.

NO_INTERIOR - This says that only the base address of the block may be a target address
              of other GC allocated pointers.
              All other possible pointers are 'false' pointers.

              Question 3: How is this different that NO_SCAN.

Perhaps I am missing the fundamentals of various D garbage collectors.

Are there any articles that expound on this issue?



Reply via email to