I have this small protobuf code (simplified, only the necessary is contained):
message ParamsMessage {
required int32 temperature = 1;
}
message MasterMessage {
enum Type { GETPARAMS = 1; SENDPARAMS = 2;}
required Type type = 1;
optional ParamsMessage paramsMessage = 2;
}
I now create a MasterMessage in the following way:
ParamsMessage * params = new ParamsMessage();
params->set_temperature(22);
MasterMessage master;
master.set_type(MasterMessage::SENDPARAMS);
master.set_allocated_paramsmessage(params);
The question is: Do I have to (after dealing with the message) delete the params
Message, or will protobuf delete it for me? I cannot find anything in the docs.
Since asking the question I have continued to find the answer. Maybe someone is interested in the answer, too.
From here: https://developers.google.com/protocol-buffers/docs/reference/cpp-generated
Which means: As long as you do not call
release_*
, protobuf will take care of deleting the object. If you need the Object after dealing with the Protobuf Message, you need to relase it usingrelease_*
, which will prevent Protobuf to delete your object.