model-writtenrun 3256 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Tom Lane opened the thread after investigating bug #18512, explaining that transaction completion selected TopMemoryContext and could turn temporary allocations into session-long leaks; he initially proposed a periodically reset context for allocations between transactions #1.
- Andres Freund warned that periodically resetting such a context could introduce difficult use-after-free bugs and suggested setting CurrentMemoryContext to NULL to force callers to choose an allocation lifetime explicitly #2.
- David Rowley proposed resetting and reusing TopTransactionContext instead of deleting and recreating it, and Tom accepted the potential efficiency benefit while rejecting the practicality of requiring every caller to select a context explicitly #3 #4.
- Tom found that leaving callers in the reused transaction context broke code, especially logical replication, because later transactions destroyed allocations that callers expected to survive; he therefore submitted a HEAD patch restoring the context active before transaction start while retaining David's context-reuse optimization #6.
- The same submission supplied a narrower alternative that explicitly saved and restored the caller's context around notify and sinval interrupt transactions; Tom proposed applying that fix to version 17 and older while reserving the broader behavior change for HEAD after branching #6.
- Andres endorsed the approach and considered hiding the persistent TopTransactionContext pointer outside transactions, but he and Tom judged the extra machinery probably unnecessary; broader resource-owner reuse was suggested as separate future work #7 #8.
- The HEAD attachment landed with only two comment wording changes as 1afe31f03c, and the older-branch attachment landed unchanged apart from branch adaptation as 8565fb6fbb, completing both fixes submitted in #6.
- Anthonin Bonnefoy subsequently reported that the restoration change could restore a deleted context when a replication command exported a snapshot, producing a self-linked memory context and an infinite deletion loop; he moved the detailed investigation to a separate thread, and no resolution appears here #9.
- Pavel Seleznev later asked whether hba.c should adopt the same allocation approach as backend initialization, and Tom declined because those callers could legitimately use different current contexts; the thread ends without another patch or a local resolution of the replication regression #10 #11.