Rework NWP memory management.
Currently, Met.3D uses data items stored in a memory manager for memory management. You need to manually keep track of the times you get, release and check for data in the memory manager, as these operations manipulate the data items ref counter. The ref counter is stored in the memory manager, meaning the data item itself does not care.
Now, when a developer stores a data item, its ref-counter is set to 1. If it does not fit, the memory manager deletes data items, that are inactive (ref counter -1).
When checking if an item is contained within the memory manager, the ref counter of the item is increased. You can decrease it by releasing the data item.
Retrieving a data item with getData
does not increase the ref counter, as it should be coupled with a contains check.
The following problems frequently arise while working with this memory management system:
- The items are not released correctly after use
- Developers are not in complete control of the references to the data item, as some references are allocated in the data pipeline by the scheduler etc. resulting in either crashes or memory leaks.
- It is not always clear, whether you need to release your data item or not. You always have to release it after checking with contains though.
Working with the memory management often introduces unwanted bugs, issues, or oversights.
It is not really transparent, as getData
does not increase the ref counter, but contains does.
Implementing a custom smart pointer system instead could automate the memory management process for the developers. Instead of worrying about the references that are still kept, they are automatically managed, as long as the smart pointer exists. One of them is always present in the memory manager, and the memory manager has access to the ref counter of them. If it needs to cleanup data items, it can just clean those, where only the memory manager has a reference to and nothing else, e.g. ref counter = 0.