While preparing my previous message 
<https://groups.google.com/d/msg/protobuf/gGAOZcfchMo/phJLrlh8BgAJ>, I 
noticed something.  It looks like, in Protobuf 3.5.1, clearing elements 
within a oneof will actually delete them (as in, call C++'s delete 
operator).  This happens whether you use MessageLite::Clear 
<https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message_lite#MessageLite.Clear.details>,
 
MessageLite::Parse* 
<https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message_lite#MessageLite.ParseFromCodedStream.details>,
 
MyMessage::my_oneof_clear_contents 
<https://developers.google.com/protocol-buffers/docs/reference/cpp-generated#oneof>,
 
or set the oneof field to hold a different subfield.  The docs and 
conventional <https://news.ycombinator.com/item?id=9161620> wisdom 
<https://groups.google.com/forum/#!topic/protobuf/b0gS4wpjuIo> generally 
encourage reuse of messages to reduce churn, but it looks like oneof's 
implementation may really strongly prefer arena allocation, which means you 
shouldn't reuse messages (since they'll never be deallocated).

Is that about right?  Would it be a good idea to document this somewhere?

Joel

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to