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