Finding memory leaks in Postgres C code
enterprisedb.com
enterprisedb.com
https://valgrind.org/docs/manual/mc-manual.html#mc-manual.mo...
See manual chapter 4.7 and 4.8:
https://valgrind.org/docs/manual/mc-manual.html#mc-manual.cl...
I would approach this problem by using regular profiling. Collect a few memory profiles and see whether there's any suspiciously large chunk of memory not yet freed.
A more vague but more useful definition of a memory leak is that if the memory consumption has a net increase over time, and that increase causes one or more problems, it's a leak.
Leaking a few kB or even MB in a short-lived client program isn't necessarily a leak in a practical sense.
Not freeing a few kB in a long-lived server process is a leak in practice if the process is going to crash or suffer degraded performance before they'll be eventually freed.
>> A more vague but more useful definition of a memory leak is that if the memory consumption has a net increase over time, and that increase causes one or more problems, it's a leak.
No. Its a problem. Caused by a leak. Your definition falls over for the case where a program is performing the task correctly, but on insufficient hardware (not enough ram) to complete the task.
PS. My assumption here is that palloc is allocating within a region. Which is how OP describes it (oddly it doesn't take a MemoryContext as an argument so that must be in some global or thread-local var, or palloc is a macro and takes the context from a lexical variable (uh)?).