Message from discussion
Issue 402 in protobuf: question for clear and parse
Received: by 10.236.153.69 with SMTP id e45mr577501yhk.35.1343361543666;
Thu, 26 Jul 2012 20:59:03 -0700 (PDT)
X-BeenThere: protobuf@googlegroups.com
Received: by 10.236.117.12 with SMTP id i12ls4619062yhh.1.gmail; Thu, 26 Jul
2012 20:59:00 -0700 (PDT)
Received: by 10.236.192.167 with SMTP id i27mr511101yhn.50.1343361540575;
Thu, 26 Jul 2012 20:59:00 -0700 (PDT)
Received: by 10.236.192.167 with SMTP id i27mr511099yhn.50.1343361540563;
Thu, 26 Jul 2012 20:59:00 -0700 (PDT)
Return-Path: <3BBISUAgOCPUmolqlYrcdlldibZlab.ZljmolqlYrcdlldibdolrmp....@codesite.bounces.google.com>
Received: from mail-yw0-f76.google.com (mail-yw0-f76.google.com [209.85.213.76])
by gmr-mx.google.com with ESMTPS id r20si106040ano.1.2012.07.26.20.59.00
(version=TLSv1/SSLv3 cipher=OTHER);
Thu, 26 Jul 2012 20:59:00 -0700 (PDT)
Received-SPF: pass (google.com: domain of 3BBISUAgOCPUmolqlYrcdlldibZlab.ZljmolqlYrcdlldibdolrmp....@codesite.bounces.google.com designates 209.85.213.76 as permitted sender) client-ip=209.85.213.76;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of 3BBISUAgOCPUmolqlYrcdlldibZlab.ZljmolqlYrcdlldibdolrmp....@codesite.bounces.google.com designates 209.85.213.76 as permitted sender) smtp.mail=3BBISUAgOCPUmolqlYrcdlldibZlab.ZljmolqlYrcdlldibdolrmp....@codesite.bounces.google.com
Received: by yhfq11 with SMTP id q11so660303yhf.3
for <protobuf@googlegroups.com>; Thu, 26 Jul 2012 20:59:00 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.224.100.137 with SMTP id y9mr2121922qan.2.1343361540472; Thu,
26 Jul 2012 20:59:00 -0700 (PDT)
Reply-To: codesite-nore...@google.com
X-Generated-By: Google Code
X-GoogleCode-Project: protobuf
X-GoogleCode-Issue-Id: 402
References: <8-13244680660385734572-6875086705591748492-protobuf=googlecode.com@googlecode.com>
<0-13244680660385734572-6875086705591748492-protobuf=googlecode.com@googlecode.com>
In-Reply-To: <8-13244680660385734572-6875086705591748492-protobuf=googlecode.com@googlecode.com>
Message-ID: <9-13244680660385734572-6875086705591748492-protobuf=googlecode....@googlecode.com>
Date: Fri, 27 Jul 2012 03:59:00 +0000
Subject: Re: Issue 402 in protobuf: question for clear and parse
From: proto...@googlecode.com
To: protobuf@googlegroups.com
Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes
Comment #9 on issue 402 by liuj...@google.com: question for clear and parse
http://code.google.com/p/protobuf/issues/detail?id=402
If we have such a message below, where Bar is a message type.
message Foo {
optional Bar bar = 1;
}
Then in C++ generated class, Foo class will have a Bar pointer for the
field, (Bar* bar;}
1) Before the first ParseFromCodedInputStream(), the bar pointer will be
NULL.
2) In the parsing function, we will new a Bar() instance and assign it to
the bar_ pointer.
3) After the foo.Clear(), we call bar.Clear() in the function, and bar will
still point to the message we allocated in the step 2.
4) The next ParseFromCodedInputStream(), we will directly merge the bytes
into the bar pointer, instead of creating a new one.
5) The allocated bar message will be deleted when the parent foo message is
destroyed.
That said, there will no memory leaks, but it's possible that you could
observe increasing memory usages in the repeated Clear() and ParseFrom().
(Imagine you have thousands of message fields, and each time there is some
message allocated) But those messages are just cached for the next
MergeFrom() to reduce the allocating cost and memory footprint. They will
be deleted once the parent message is deleted. If you find the memory usage
is increasing linearly and boundlessly, then there must be something wrong
in your code.