[英]Does Boost.Serialization Free the Memory Created during Loading Pointers?
To be specific, I'm referring to the demo in Boost.Serialization tutorial here . 具体而言,我指的是在Boost.Serialization教程演示这里 。
In the above demo, bus_top
instances are stored as pointers in bus_route
to showcase how serialization of pointers is achieved. 在上面的演示中,
bus_top
实例作为指针存储在bus_route
以展示如何实现指针的序列化。 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()
. 但是,我观察到一个有趣的行为,即从不为
restore_schedule()
创建的bus_stop
对象调用析构函数bus_stop::~bus_stop()
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. 我在
bus_stop::~bus_stop()
设置了一个断点,它只是由main
函数末尾的delete
语句触发。
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. 在加载序列化数据期间,初始化指针的对象在
boost/archive/detail/iserializer.hpp
定义的pointer_iserializer
中分配,该heap_allocator
使用heap_allocator
来分配空间。
They do have a destroy
function to release allocated memory in boost/serialization/access.hpp
, but seems never got invoked. 它们有一个
destroy
函数来释放boost/serialization/access.hpp
分配内存,但似乎从来没有被调用过。
Is it correct that Boost.Serialization does not manage the pointers created during loading data? Boost.Serialization不管理加载数据期间创建的指针是否正确?
Conclusions: 结论:
new
(ie boost::archive::detail::heap_allocator
, boost::serialization::access::construct
) new
创建(即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::access::destroy
,但据我所知,它没有得到在调用boost
的任何地方。 boost::serialization
, using delete
(or boost::serialization::access::destroy
if you like). boost::serialization
分配的对象,使用delete
(如果你愿意,可以使用boost::serialization::access::destroy
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.