Re: Proposal for fixing intra-query memory leaks

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Proposal for fixing intra-query memory leaks
Date: 2000-05-02 21:29:06
Message-ID: Pine.LNX.4.21.0005020049550.389-100000@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thanks for the timely introduction to memory contexts btw. :)

> 1. There will be two kinds of contexts, "permanent" and "temporary".

Rather than making this an explicit distinction you could simply (hah)
make the transaction initiating command create a memory context under Top
and store a pointer to it in a global variable. Then per tuple contexts,
etc. are created as a child thereof. The transaction ending commands would
then destroy that context again. I guess this is sort of what you were
planning anyway but I just wanted to throw in that specially treating this
"everything lives and dies with the transaction" attitude is not the
be-all-end-all, IMHO. ("Statement" would be better than "transaction" in
many cases anyway.)

> Functions that return pass-by-reference values will be required always
> to palloc the returned space in the caller's memory context (ie, the
> context that was CurrentMemoryContext at the time of call). It is not
> OK to pass back an input pointer, even if we are returning an input value
> verbatim, because we do not know the lifespan of the context the input
> pointer points to.

ISTM that you can have the compiler help you here if you separate input
and output values in the function manager design. E.g., if you define the
function signature like

void my_func(const fmgr_in_t * in, fmgr_out_t * out);

then you establish the fact that copying is required.

--
Peter Eisentraut Sernanders väg 10:115
peter_e(at)gmx(dot)net 75262 Uppsala
http://yi.org/peter-e/ Sweden

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2000-05-02 21:35:57 Re: shmem_seq may be a bad idea
Previous Message Peter Eisentraut 2000-05-02 21:28:14 Re: RE: [PATCHES] relation filename patch