Re: MemoryContextCreate change in PG 11 how should contexts be created - Mailing list pgsql-hackers

From Paul Ramsey
Subject Re: MemoryContextCreate change in PG 11 how should contexts be created
Date
Msg-id CACowWR0iWnedo9JCS-eh6Efu6n6QmVZZsvr6YgjjhTnrN5jsQw@mail.gmail.com
Whole thread Raw
In response to Re: MemoryContextCreate change in PG 11 how should contexts becreated  (Alvaro Herrera <alvherre@2ndquadrant.com>)
List pgsql-hackers
On Tue, Dec 19, 2017 at 6:54 AM, Alvaro Herrera
<alvherre@2ndquadrant.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


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: MemoryContextCreate change in PG 11 how should contexts be created
Next
From: Paul Ramsey
Date:
Subject: Re: MemoryContextCreate change in PG 11 how should contexts be created