On 23/08/2009 12:42 PM, Greg Stark wrote:
On Sun, Aug 23, 2009 at 4:48 AM, Craig
Ringer<cr...@postnewspapers.com.au> wrote:
Interestingly, though, the test program does appear to be leaking - at
least, the peak working set slowly climbs. It's all private working set. Not
sure why yet since the memory use looks like it _should_ be constant.
How does the return value of str() get cleaned up here?
PGresult* res=PQexec(conn,insert.str().c_str());
str() returns a std::string instance by value. It's not returning a
pointer to a heap allocated object. The returned std::string is cleaned
up when it leaves scope - in this case, at end-of-statement.
c_str() is called on the temporary std::string . This returns a const
char * to a block of memory owned by the std::string . It must *NOT* be
freed by the caller or modified by the caller. It's usually just the
internal buffer maintained by the std::string. See:
http://www.cplusplus.com/reference/string/string/c_str/
So, no, there's no leak there.
--
Craig Ringer
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs