Search Postgresql Archives

Re: Detecting memory leaks with libpq?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19/07/2011 6:41 PM, Antonio Vieiro wrote:
Hi all,

I'm building a small C application that uses libpq and I was wondering
if there's an easy way to detect memory leaks in my code.

I think I'm calling PQclear and friends correctly, but I'd like to
double-check it. I was wondering if there's a function in libpq to
check memory-use usage/internals, or something like that.

If I genuinely suspected a leak and running the code in a loop showed continually increasing memory use, I'd use valgrind to try to track it down. Just like for any other kind of leak checking.

Note that some "leaks" that are reported are _normal_ in most software. There is absolutely no harm in not free()ing a structure that's allocated only once during init and never messed with afterwards. The OS clears the memory anyway, so free()ing it is just a waste of CPU cycles.

What you need to look for is patterns where memory is _repeatedly_ allocated and not free()'d . For that, you need to run quite a few repetitions within one process so you can tell the difference between the one-offs and genuine leaks.

--
Craig Ringer

POST Newspapers
276 Onslow Rd, Shenton Park
Ph: 08 9381 3088     Fax: 08 9388 2258
ABN: 50 008 917 717
http://www.postnewspapers.com.au/

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux