diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2015-02-27 18:09:42 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2015-02-27 18:10:04 -0500 |
commit | eaa5808e8ec4e82ce1a87103a6b6f687666e4e4c (patch) | |
tree | bd0ea9beab48b3939190ec56c9913a5d1466d53e /src/backend/utils/mmgr/mcxt.c | |
parent | fbef4342a86522c98cd605891ad8c1145a61d191 (diff) |
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.
Diffstat (limited to 'src/backend/utils/mmgr/mcxt.c')
-rw-r--r-- | src/backend/utils/mmgr/mcxt.c | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 72a32abdddb..e2fbfd420b6 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -132,11 +132,8 @@ MemoryContextInit(void) /* * MemoryContextReset - * Release all space allocated within a context and its descendants, - * but don't delete the contexts themselves. - * - * The type-specific reset routine handles the context itself, but we - * have to do the recursion for the children. + * Release all space allocated within a context and delete all its + * descendant contexts (but not the named context itself). */ void MemoryContextReset(MemoryContext context) @@ -145,7 +142,22 @@ MemoryContextReset(MemoryContext context) /* save a function call in common case where there are no children */ if (context->firstchild != NULL) - MemoryContextResetChildren(context); + MemoryContextDeleteChildren(context); + + /* save a function call if no pallocs since startup or last reset */ + if (!context->isReset) + MemoryContextResetOnly(context); +} + +/* + * MemoryContextResetOnly + * Release all space allocated within a context. + * Nothing is done to the context's descendant contexts. + */ +void +MemoryContextResetOnly(MemoryContext context) +{ + AssertArg(MemoryContextIsValid(context)); /* Nothing to do if no pallocs since startup or last reset */ if (!context->isReset) @@ -172,7 +184,10 @@ MemoryContextResetChildren(MemoryContext context) AssertArg(MemoryContextIsValid(context)); for (child = context->firstchild; child != NULL; child = child->nextchild) - MemoryContextReset(child); + { + MemoryContextResetChildren(child); + MemoryContextResetOnly(child); + } } /* @@ -235,23 +250,6 @@ MemoryContextDeleteChildren(MemoryContext context) } /* - * MemoryContextResetAndDeleteChildren - * Release all space allocated within a context and delete all - * its descendants. - * - * This is a common combination case where we want to preserve the - * specific context but get rid of absolutely everything under it. - */ -void -MemoryContextResetAndDeleteChildren(MemoryContext context) -{ - AssertArg(MemoryContextIsValid(context)); - - MemoryContextDeleteChildren(context); - MemoryContextReset(context); -} - -/* * MemoryContextRegisterResetCallback * Register a function to be called before next context reset/delete. * Such callbacks will be called in reverse order of registration. |