Re: Which MemoryContext?

From: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
To: "Gevik Babakhani" <pgdev(at)xs4all(dot)nl>
Cc: "'pgsql-hackers'" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Which MemoryContext?
Date: 2008-02-20 23:47:26
Message-ID: 47BCBC0E.4070603@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Gevik Babakhani wrote:
> I have allocated memory using: MemoryContextAlloc(TopMemoryContext,n *
> sizeof(char*));
> In pgsql/src/backend/utils/mmgr/README:142 is stated that memory allocated
> using above should be freed manually, Is this correct? Or does the system
> release everything allocated in TopMemoryContext automatically when exiting?

On backend exit, everything in TopMemoryContext, like all other
non-shared memory, is automatically released.

> I looked around and found examples where memory allocated
> using above is not freed! (datetime.c:3811, uhhh.. a bit confused here)

That palloc'd table in datetime.c is kept until backend exit, or until
it's replaced with a new table. If it's replaced with a new table, the
old one is explicitly pfree'd in that function:

> /* Now safe to replace existing table (if any) */
> if (timezonetktbl)
> pfree(timezonetktbl);

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joshua D. Drake 2008-02-20 23:51:06 Re: Permanent settings
Previous Message Tom Lane 2008-02-20 23:38:10 Re: Permanent settings