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: signature.asc
Description: PGP signature

Reply via email to