As I know, tools for managing object lifetime are :-
- std::unique_ptr
- std::move
- move constructor
- move assignment
- delete copy constructor
- delete copy assigment
With those tools, it is very obvious to determine owner of any certain object - the owner is the one who stores std::unique_ptr as a field.
However, it is obscure which class actually controls memory allocation.
There are only few tools to help :-
- the second template parameter of std::unique_ptr
- the second template parameter of std::vector and other datastructure
None of them indicate which instance of allocator is the ownership of such address.
In a scope of class, it is alarming that underlying memory of a std::unique_ptr (that a class owns) can be deallocated any times. (e.g. from pop operation of scope allocators).
std::unique_ptr<SomeThing> a=scopeAllocator->makeUnique<SomeThing>();
scopeAllocator->pop();
//memory of "a" is invalid!
Are there any tools/techniques to help/prevent it, or at least make thing more obvious for coder?