Re: Detecting memory leaks with libpq?
От | Craig Ringer |
---|---|
Тема | Re: Detecting memory leaks with libpq? |
Дата | |
Msg-id | 4E25868E.4070204@postnewspapers.com.au обсуждение исходный текст |
Ответ на | Detecting memory leaks with libpq? (Antonio Vieiro <antonio@antonioshome.net>) |
Ответы |
Re: Detecting memory leaks with libpq?
|
Список | pgsql-general |
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/
В списке pgsql-general по дате отправления: