NSAllocDebugZone class
The NSDefaultZone uses system malloc, calloc,
realloc and free directly, without any checks.
The NSAllocDebugZone is used to help in tracking down memory
allocation bugs. It provides the following features:
SYSTEM_MALLOC_CHECK and internal checks every count operation
The NSAllocDebugZone is controlled by the following environment
variables:
ALLOCDEBUG: must be set to something to use the alloc debug zone
ALLOCDEBUG_STOP: stop in debugger SIGINT when alloc-ing
pointer with given serial number (this serial number is reported when
and error with that pointer occurs). Undefined or 0 means no stop.
ALLOCDEBUG_COUNT: number of passes inside allocation/deallocation
functions to SYSTEM_MALLOC_CHECK and internal check. Undefined or
0 means no checks.
ALLOCDEBUG_UPPER and ALLOCDEBUG_LOWER: number of bytes to alloc at top/bottom of
object block. These bytes are set to a given value (0x88) and checked at
free and internal check to guard against using memory past the
limit. Undefined or zero means no margin. Note that this size must be
multiples of the machine address alignment (4, 8, 16 are recommended
values).
The NSAllocDebugZone provides these functions to be used from the
GNU debugger.
debuggerStopMark(unsigned mark): overrides ALLOCDEBUG_STOP
debuggerCheckTime(unsigned count): overrides ALLOCDEBUG_COUNT
debuggerDescription(id obj): performs printf("%s\n", [obj description])
debuggerPerform(id obj, char* sel): performs [obj sel]
debuggerPerformWith(id obj, char* sel, id arg): performs [obj sel:(id)atoi(arg)]
The program instantiates two zones: one NSDefaultZone and one
NSAllocDebugZone, and uses one or the other depending on the
ALLOCDEBUG environment variable. If this variable exists in your
environment then the NSAllocDebugZone instance will be
used.
Below are some setting you might find useful when working with the
NSAllocDebugZone class.
# must be set to something to use alloc debug zone ALLOCDEBUG=YES export ALLOCDEBUG=YES # stop in debugger (SIGINT) when alloc-ing pointer number * # nil or 0 means no stop ALLOCDEBUG_STOP=0 export ALLOCDEBUG_STOP # stop in debugger (SIGINT) when alloc-ing pointer number * # nil or 0 means no stop ALLOCDEBUG_MARK=0 export ALLOCDEBUG_MARK # number of passes inside allocation/deallocation functions # to SYSTEM_MALLOC_CHECK and internal check # nil or 0 means no checks ALLOCDEBUG_COUNT=16 export ALLOCDEBUG_COUNT # number of bytes to alloc at top/bottom of object block # these bytes are set to a given value (0x88) and checked # at free and internal check to guard against using memory # past the limit. ALLOCDEBUG_UPPER=8 ALLOCDEBUG_LOWER=8 export ALLOCDEBUG_UPPER ALLOCDEBUG_LOWER
Go to the first, previous, next, last section, table of contents.