src/backend/utils/mmgr/mcxt.c
void
MemoryContextDelete(MemoryContext context)
{
	AssertArg(MemoryContextIsValid(context));
	/* We had better not be deleting TopMemoryContext ... */
	Assert(context != TopMemoryContext);
	/* And not CurrentMemoryContext, either */
	Assert(context != CurrentMemoryContext);

	/* save a function call in common case where there are no children */
	if (context->firstchild != NULL)
		MemoryContextDeleteChildren(context);

	/*
	 * It's not entirely clear whether 'tis better to do this before or after
	 * delinking the context; but an error in a callback will likely result in
	 * leaking the whole context (if it's not a root context) if we do it
	 * after, so let's do it before.
	 */
	MemoryContextCallResetCallbacks(context);

	/*
	 * We delink the context from its parent before deleting it, so that if
	 * there's an error we won't have deleted/busted contexts still attached
	 * to the context tree.  Better a leak than a crash.
	 */
	MemoryContextSetParent(context, NULL);

	/*
	 * Also reset the context's ident pointer, in case it points into the
	 * context.  This would only matter if someone tries to get stats on the
	 * (already unlinked) context, which is unlikely, but let's be safe.
	 */
	context->ident = NULL;

	context->methods->delete_context(context);

	VALGRIND_DESTROY_MEMPOOL(context);
}
/*
 * MemoryContextDelete
 *		Delete a context and its descendants, and release all space
 *		allocated therein.
 *
 * The type-specific delete routine removes all storage for the context,
 * but we have to recurse to handle the children.
 * We must also delink the context from its parent, if it has one.
 */
MemoryContextDelete
Delete a context and its descendants, and release all space
allocated therein.

The type-specific delete routine removes all storage for the context,
but we have to recurse to handle the children.
We must also delink the context from its parent, if it has one.
MemoryContextDelete Delete a context and its descendants and release all space allocated therein . The type - specific delete routine removes all storage for the context but we have to recurse to handle the children . We must also delink the context from its parent if it has one .
void
MemoryContextDelete(MemoryContext context)
{
	AssertArg(MemoryContextIsValid(context));
	Assert(context != TopMemoryContext);
	Assert(context != CurrentMemoryContext);
	if (context->firstchild != NULL)
		MemoryContextDeleteChildren(context);
	MemoryContextCallResetCallbacks(context);
	MemoryContextSetParent(context, NULL);
	context->ident = NULL;
	context->methods->delete_context(context);
	VALGRIND_DESTROY_MEMPOOL(context);
}
void MemoryContextDelete ( MemoryContext context ) { AssertArg ( MemoryContextIsValid ( context ) ) ; Assert ( context != TopMemoryContext ) ; Assert ( context != CurrentMemoryContext ) ; if ( context -> firstchild != NULL ) MemoryContextDeleteChildren ( context ) ; MemoryContextCallResetCallbacks ( context ) ; MemoryContextSetParent ( context , NULL ) ; context -> ident = NULL ; context -> methods -> delete_context ( context ) ; VALGRIND_DESTROY_MEMPOOL ( context ) ; }
MemoryContextDelete
              Delete a context and its descendants, and release all space
              allocated therein.
MemoryContextDelete Delete a context and its descendants and release all space allocated therein .
/* We had better not be deleting TopMemoryContext ... */ /* And not CurrentMemoryContext, either */ /* save a function call in common case where there are no children */ /*
	 * It's not entirely clear whether 'tis better to do this before or after
	 * delinking the context; but an error in a callback will likely result in
	 * leaking the whole context (if it's not a root context) if we do it
	 * after, so let's do it before.
	 */ /*
	 * We delink the context from its parent before deleting it, so that if
	 * there's an error we won't have deleted/busted contexts still attached
	 * to the context tree.  Better a leak than a crash.
	 */ /*
	 * Also reset the context's ident pointer, in case it points into the
	 * context.  This would only matter if someone tries to get stats on the
	 * (already unlinked) context, which is unlikely, but let's be safe.
	 */