To be specific, I'm referring to the demo in Boost.Serialization tutorial here.
In the above demo, bus_top
instances are stored as pointers in bus_route
to showcase how serialization of pointers is achieved. However, I observed an interesting behavior, that is, the destructor bus_stop::~bus_stop()
is never invoked for the bus_stop
objects created by restore_schedule()
. I put a break point in bus_stop::~bus_stop()
and it was triggered only by the delete
statements at the end of main
function.
During loading serialized data, objects to initialize pointers are allocated in pointer_iserializer
defined in boost/archive/detail/iserializer.hpp
, which uses a heap_allocator
to allocate space.
They do have a destroy
function to release allocated memory in boost/serialization/access.hpp
, but seems never got invoked.
Is it correct that Boost.Serialization does not manage the pointers created during loading data?
Conclusions:
new
(i.e. boost::archive::detail::heap_allocator
, boost::serialization::access::construct
)boost::serialization::access::destroy
, but AFAIK, it's not got invoked in boost
anywhere. boost::serialization
, using delete
(or boost::serialization::access::destroy
if you like).