Memory

palloc / pfree

Also called: palloc, pfree, MemoryContextAlloc

palloc(size) is PostgreSQL's internal allocator call. Unlike malloc, it takes no context argument, it allocates from the global CurrentMemoryContext, so where the memory lands depends on the context in effect. pfree releases one chunk, but it is rarely used: the normal pattern is to let the context be reset or deleted later.

What this means

Postgres's own version of malloc. The twist: palloc takes no "where" argument, it allocates from whatever memory context is currently in effect, so the same call lands in different arenas depending on context. pfree releases one chunk, but it's rarely needed; usually you just let the whole context be reset later.

Why it matters operationally

Because palloc follows CurrentMemoryContext, the same call can put memory in a short-lived per-tuple arena or a long-lived cache depending on the surrounding MemoryContextSwitchTo. Allocating in the wrong context is the canonical PostgreSQL memory leak.

← All glossary terms · GUC reference · Error catalog