Hello everybody,

I've got a strange behaviour when using a message with a repeated
attribute inside.

This is a very simplified example:

message Input
   required bytes content = 1;
   required bytes sender = 2;
   required bytes rcpt = 3;

message Response
  repeated Input entries = 1;

Response response;
google::protobuf::RepeatedPtrField<Input>* entries =

for(int i=0;i<10000;++i)
        std::auto_ptr<Input> in = createInputEntry();
        std::string serialized = in->SerializeAsString();

        Input* entry = response.add_entries();
        entry->ParseFromArray(serialized.data(), serialized.length());

std::string serializedResponse = response.SerializeAsString();


The createInputEntry and serialization does not make in this example
any sense, but it is a simplified scenario what happens in the real

I was expecting that when Response is out of scope the memory usage
should get back to the initial memory size, but unfortunately this
does not happen. In my test case (it is not the initial size is around
2MB, after inserting some entries it increases up to 9MB and the
memory is not released.

The behaviour changes in case I resize the pointer array to lets say
10000 in this example. After Response is out of scope the memory usage
is the same as at the beginning. But If I reserve more than entries
are created the inital behaviour comes back.

I am not totally sure what happens at that point. Maybe someone could
explain this strange behaviour.

Thanks in advance.

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to