src/backend/utils/mmgr/slab.c
static void
SlabReset(MemoryContext context)
{
	int			i;
	SlabContext *slab = castNode(SlabContext, context);

	Assert(slab);

#ifdef MEMORY_CONTEXT_CHECKING
	/* Check for corruption and leaks before freeing */
	SlabCheck(context);
#endif

	/* walk over freelists and free the blocks */
	for (i = 0; i <= slab->chunksPerBlock; i++)
	{
		dlist_mutable_iter miter;

		dlist_foreach_modify(miter, &slab->freelist[i])
		{
			SlabBlock  *block = dlist_container(SlabBlock, node, miter.cur);

			dlist_delete(miter.cur);

#ifdef CLOBBER_FREED_MEMORY
			wipe_mem(block, slab->blockSize);
#endif
			free(block);
			slab->nblocks--;
			context->mem_allocated -= slab->blockSize;
		}
	}

	slab->minFreeChunks = 0;

	Assert(slab->nblocks == 0);
	Assert(context->mem_allocated == 0);
}
/*
 * SlabReset
 *		Frees all memory which is allocated in the given set.
 *
 * The code simply frees all the blocks in the context - we don't keep any
 * keeper blocks or anything like that.
 */
SlabReset
Frees all memory which is allocated in the given set.

The code simply frees all the blocks in the context - we don't keep any
keeper blocks or anything like that.
SlabReset Frees all memory which is allocated in the given set . The code simply frees all the blocks in the context - we don ' t keep any keeper blocks or anything like that .
static void
SlabReset(MemoryContext context)
{
	int			i;
	SlabContext *slab = castNode(SlabContext, context);
	Assert(slab);
#ifdef MEMORY_CONTEXT_CHECKING
	SlabCheck(context);
#endif
	for (i = 0; i <= slab->chunksPerBlock; i++)
	{
		dlist_mutable_iter miter;
		dlist_foreach_modify(miter, &slab->freelist[i])
		{
			SlabBlock  *block = dlist_container(SlabBlock, node, miter.cur);
			dlist_delete(miter.cur);
#ifdef CLOBBER_FREED_MEMORY
			wipe_mem(block, slab->blockSize);
#endif
			free(block);
			slab->nblocks--;
			context->mem_allocated -= slab->blockSize;
		}
	}
	slab->minFreeChunks = 0;
	Assert(slab->nblocks == 0);
	Assert(context->mem_allocated == 0);
}
static void SlabReset ( MemoryContext context ) { int i ; SlabContext * slab = castNode ( SlabContext , context ) ; Assert ( slab ) ; #ifdef MEMORY_CONTEXT_CHECKING SlabCheck ( context ) ; #endif for ( i = 0 ; i <= slab -> chunksPerBlock ; i ++ ) { dlist_mutable_iter miter ; dlist_foreach_modify ( miter , & slab -> freelist [ i ] ) { SlabBlock * block = dlist_container ( SlabBlock , node , miter . cur ) ; dlist_delete ( miter . cur ) ; #ifdef CLOBBER_FREED_MEMORY wipe_mem ( block , slab -> blockSize ) ; #endif free ( block ) ; slab -> nblocks -- ; context -> mem_allocated -= slab -> blockSize ; } } slab -> minFreeChunks = 0 ; Assert ( slab -> nblocks == 0 ) ; Assert ( context -> mem_allocated == 0 ) ; }
SlabReset
              Frees all memory which is allocated in the given set.
SlabReset Frees all memory which is allocated in the given set .
/* Check for corruption and leaks before freeing */ /* walk over freelists and free the blocks */