Re: Extended Statistics set/restore/clear functions. - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Extended Statistics set/restore/clear functions.
Date
Msg-id aW68-vC2fkQ54pLC@paquier.xyz
Whole thread Raw
In response to Re: Extended Statistics set/restore/clear functions.  (Chao Li <li.evan.chao@gmail.com>)
List pgsql-hackers
On Mon, Jan 19, 2026 at 04:56:25PM +0800, Chao Li wrote:
> Should tuples returned by SearchSysCacheCopy1() always be explicitly
> freed with heap_freetuple()? I’ve long had the understanding that
> the answer is “yes”.
>
> However, recently I’ve seen some patches addressing apparent memory
> leaks deemed unnecessary on the grounds that the surrounding memory
> context would clean things up anyway. That made me unsure whether
> the same reasoning is considered acceptable for tuples returned by
> SearchSysCacheCopy1(), or whether the expectation is still that
> callers should free them explicitly.

My guess is that it depends on the context where a given function is
called.  If for example SearchSysCacheCopy1() is used in something in
a tight loop, freeing memory is justified to me.  A SQL function would
have its execution memory context pretty quickly, though, so a free()
would make less sense.  So there is no strict rule on the matter, one
or other other may make more sense.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Add WALRCV_CONNECTING state to walreceiver
Next
From: Michael Paquier
Date:
Subject: Some cleanup of pg_stat_statements tests