Open
Description
The churn_allocator
causes memory coupling between modules which use the TrajectoryStateOnSurface class. This makes it difficult to look for memory issues within a module as memory allocation/deallocation spans across module boundaries.A possible change could use a ChurnManager
class which is put onto the stack and then the manager is passed to the churn_allocator
's constructor. This would alleviate the need for a thread_local
as the manager's lifetime would be limited to one thread. When the ChurnManager
goes out of scope, it would make sure the cache is properly released if necessary (unlike now where the cache's pointer is never deleted). To avoid possible problems where the lifetime of the copied churn_allocator
is longer than ChurnManger
, the churn_allocator
could hold a std::weak_pointer
to the cache and if the cache is already gone the memory will just be deallocated.