I'm serializing and sending a raw-pointer of an object to another application.
When deserializing I'm getting another raw-pointer. This means that Boost::Serialization is constructing the object behind this pointer internally. I'm now curious who has ownership of the object and if Boost will delete that object, if it isn't needed anymore.
Some code which perhaps better shows what the question is:
void anyMethod()
{
std::ifstream file("archiv.txt");
boost::archive::text_iarchive ia(file);
AnyClass* object;
ia >> object;
//work with object
}
//Now what has happened to object?
//Is it deleted, cause it went out of scope?
//Do I have to delete it myself?
My understanding of the documentation regarding pointers serialization is that ownership is kept by the archive : "Loading the same pointer object multiple times results in only one object being created, thereby replicating the original pointer configuration". This tends to indicate that the library handles the book keeping.
Furthermore, the archive provides a delete_created_pointers
method : "Deletes all objects created by the loading of pointers. This can be used to avoid memory leaks that might otherwise occur if pointers are being loaded and the archive load encounters an exception".