Re: Which MemoryContext? - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: Which MemoryContext?
Date
Msg-id 47BCBC0E.4070603@enterprisedb.com
Whole thread Raw
In response to Re: Which MemoryContext?  ("Gevik Babakhani" <pgdev@xs4all.nl>)
Responses Re: Which MemoryContext?  ("Gevik Babakhani" <pgdev@xs4all.nl>)
List 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


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Permanent settings
Next
From: "Joshua D. Drake"
Date:
Subject: Re: Permanent settings