Re: [HACKERS] Which MemoryContext?

2008-02-21 Thread Gevik Babakhani
> All local memory is safe to handle that way. In my case I am reallocating memory for a global variable between transactions. I wanted to make sure I don't leave allocated memory behind. > The problem only arises when you have memory to release _earlier_ than that. First I was looking for a way

Re: [HACKERS] Which MemoryContext?

2008-02-20 Thread Alvaro Herrera
Gevik Babakhani wrote: > > On backend exit, everything in TopMemoryContext, like all > > other non-shared memory, is automatically released. > > So it is safe to not free the allocated memory in TopMemoryContext and leave > it to be released on backend exit. All local memory is safe to handle th

Re: [HACKERS] Which MemoryContext?

2008-02-20 Thread Gevik Babakhani
> On backend exit, everything in TopMemoryContext, like all > other non-shared memory, is automatically released. > So it is safe to not free the allocated memory in TopMemoryContext and leave it to be released on backend exit. Thank you for the help :) Regards, Gevik. --

Re: [HACKERS] Which MemoryContext?

2008-02-20 Thread Heikki Linnakangas
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 TopMem

Re: [HACKERS] Which MemoryContext?

2008-02-20 Thread Gevik Babakhani
> TopMemoryContext sounds right. Be careful not to leak there. Thank you :) 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 d

Re: [HACKERS] Which MemoryContext?

2008-02-20 Thread Heikki Linnakangas
Gevik Babakhani wrote: I want to keep an array of localized strings in memory. This array is dynamically allocated and is going to be used between transactions (that are not necessarily nested). It must be cleaned/freed when postmaster exists. In which context should this array be initialized?

[HACKERS] Which MemoryContext?

2008-02-20 Thread Gevik Babakhani
Hi, I want to keep an array of localized strings in memory. This array is dynamically allocated and is going to be used between transactions (that are not necessarily nested). It must be cleaned/freed when postmaster exists. In which context should this array be initialized? TopMemoryContext pe