Thread: pgsql: Redefine MemoryContextReset() as deleting, not resetting, child

pgsql: Redefine MemoryContextReset() as deleting, not resetting, child

From
Tom Lane
Date:
Redefine MemoryContextReset() as deleting, not resetting, child contexts.

That is, MemoryContextReset() now means what was formerly meant by
MemoryContextResetAndDeleteChildren(), and the latter is now just a macro
alias for the former.  If you really want the functionality that was
formerly provided by MemoryContextReset(), what you have to do is
MemoryContextResetChildren() plus MemoryContextResetOnly() (which is a
new API to reset *only* the named context and not touch its children).

The reason for this change is that near fifteen years of experience has
proven that there is noplace where old-style MemoryContextReset() is
actually what you want.  Making that the default behavior has led to lots
of context-leakage bugs, while we've not found anyplace where it's actually
necessary to keep the child contexts; at least the standard regression
tests do not reveal anyplace where this change breaks anything.  And there
are upcoming patches that will introduce additional reasons why child
contexts need to be removed.

We could change existing calls of MemoryContextResetAndDeleteChildren to be
just MemoryContextReset, but for the moment I'll leave them alone; they're
not costing anything.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/eaa5808e8ec4e82ce1a87103a6b6f687666e4e4c

Modified Files
--------------
src/backend/utils/mmgr/README |   11 +++++++---
src/backend/utils/mmgr/mcxt.c |   46 ++++++++++++++++++++---------------------
src/include/utils/memutils.h  |    5 ++++-
3 files changed, 34 insertions(+), 28 deletions(-)