Skip site navigation (1) Skip section navigation (2)

Re: Bug #548: Misleading documentation of `palloc'

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: hkrug(at)rationalizer(dot)com, pgsql-bugs(at)postgresql(dot)org
Subject: Re: Bug #548: Misleading documentation of `palloc'
Date: 2002-01-03 08:13:38
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugs
Developer's FAQ updated to:

    <P><I>palloc()</I> and <I>pfree()</I> are used in place of malloc()
    and free() because we find it easier to automatically free all
    memory allocated when a query completes. This assures us that all
    memory that was allocated gets freed even if we have lost track of
    where we allocated it. There are special non-query contexts that
    memory can be allocated in. These affect when the allocated memory
    is freed by the backend.</P>


pgsql-bugs(at)postgresql(dot)org wrote:
> Holger Krug (hkrug(at)rationalizer(dot)com) reports a bug with a severity of 2
> The lower the number the more severe it is.
> Short Description
> Misleading documentation of `palloc'
> Long Description
> In section 12.5.6 "Writing Code" of the "PostgreSQL 7.2 Programmer's 
> Guide" the following is said:
> "When allocating memory, use the PostgreSQL routines `palloc' and
> `pfree' instead of the corresponding C library routines `malloc' and
> `free'. The memory allocated by `palloc' will be freed automatically
> at the end of each transaction, preventing memory leaks."
> This is not actually wrong but *misleading*, because memory allocated by `palloc' in a user-defined server-side C language function is freed not only at transaction end but actually at the end of each TransactionCommand - or even more: at the end of each expression evaluation. The reason is, that the `CurrentMemoryContext' used for the evaluation of such functions is `PlanExprContext', which is a
> child of `TransactionCommandContext', which is a child of
> `TopTransactionContext'.

  Bruce Momjian                        |
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

In response to

pgsql-bugs by date

Next:From: Shahid Mohammad ShamsiDate: 2002-01-03 16:11:09
Subject: select table privilege in postgres allows user to create index on the table
Previous:From: Bruce MomjianDate: 2002-01-03 05:57:13
Subject: Re: After ~Crash Sequence not correct

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group