Re: MemoryContextCreate change in PG 11 how should contexts be created

From: Paul Ramsey <pramsey(at)cleverelephant(dot)ca>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Regina Obe <lr(at)pcorp(dot)us>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: MemoryContextCreate change in PG 11 how should contexts be created
Date: 2017-12-19 15:05:28
Message-ID: CACowWR0iWnedo9JCS-eh6Efu6n6QmVZZsvr6YgjjhTnrN5jsQw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Dec 19, 2017 at 6:54 AM, Alvaro Herrera
<alvherre(at)2ndquadrant(dot)com> wrote:
> Paul Ramsey wrote:
>
>> Our use of MemoryContextCreate is solely in order to get use
>> MemoryContextDelete as a callback so that, at the end of a statement,
>> we can clean up externally allocated memory that we're holding in a
>> cache.
>
> You should not use MemoryContextCreate at all -- it's somewhat of an
> internal API, as you could guess by looking at the weird arguments that
> you're forced into passing.
>
> Instead, the interface you're supposed to use is AllocSetContextCreate.
> Just make sure you attach your new context to one which has the right
> lifetime for your usage -- in your case ISTM the parent should be
> PortalContext, which makes it go away when the current portal (query) is
> gone.

Thanks, it looks like PortalContext will serve perfectly.

P

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Paul Ramsey 2017-12-19 15:11:05 Re: MemoryContextCreate change in PG 11 how should contexts be created
Previous Message Tom Lane 2017-12-19 15:00:54 Re: MemoryContextCreate change in PG 11 how should contexts be created