Dana uses a hybrid approach to memory management. In most cases this will appear fully automated, where any allocated memory is automatically cleaned up for you by the language, and so there's nothing that you need to do as a programmer.

However, understanding the detail of Dana's memory management approach will help you to know when you don't get full automation and so will need to explicitly assist with your own code.

Dana defines two kinds of memory usage: managed and unmanaged.

Managed memory is that which has been created by an object by instantiating data items, arrays, and objects. As long as these items are referenced by their creating object, we call them managed. Dana uses a simple reference-counting garbage collector for managed memory, which means that when the number of references to an element reach zero the system will automatically clean up the memory of that element. However, Dana will not check for circular references in managed memory and so the programmer is responsible for explicitly breaking any such circular references in order to allow memory to be cleaned up.

Unmanaged memory is any data instance or array which has been passed to an object that did not create it, where the creating object no longer has a reference to it. In this case, the owner of the instance is no longer “managing” the memory, so Dana's full cycle-detecting garbage collector operates on these instances to automatically detect circular references and free the memory when it is no longer referenced.