NSZone class
NSZone is an abstract class that defines the basic behavior for
all the memory allocators.
+(void)setDefaultZone:(NSZone*)zone;
Sets the default zone from which the subsequent memory allocation takes place.
+(NSZone*)defaultZone;
Returns the default zone.
+(NSZone*)zoneFromPointer:(void*)pointer;
Returns the zone from which pointer was allocated. Care should be taken as the zones are asked (using
-pointerInZone:) in order if the pointer was allocated by them. See the-pointerInZone:method description for more information.
+(BOOL)checkZone;
Check the memory allocated by all the zones. See the
-checkZonemethod description for more information.
+(id)allocZoneInstance;
This is the low level method used to allocate a zone instance. This is used because allocation of zone instances is done in a special way to avoid the chicken and egg problem (from which zone a zone instance is allocated?)
-(id)initForSize:(unsigned)startSize granularity:(unsigned)granularity
canFree:(BOOL)canFree;
This is the designated initialization method. Creates a zone that can allocate as much as startSize memory initially. The memory can grow or shrink in increments of granularity. If canFree is set to
YESthe memory is freed when when-free:is sent, otherwise the memory is never freed.
-(void*)malloc:(unsigned)size;
Allocate a memory zone of size bytes and return it. Returns
NULLif this is not possible.
-(void*)mallocAtomic:(unsigned)size;
Similar with
-malloc:but allocate a memory zone that's not searched by the garbage collector for pointers.
-(void*)calloc:(unsigned)numElems byteSize:(unsigned)byteSize;
Allocate a memory zone that holds numElems elements, each of byteSize, set all the bytes in it to
0and return it. ReturnsNULLif the allocation fails.
-(void*)callocAtomic:(unsigned)numElems byteSize:(unsigned)byteSize;
Similar with
-calloc:byteSize:but return a memory zone that's not searched by the garbage collector for pointers.
-(void*)realloc:(void*)pointer size:(unsigned)size;
Grow or shrink the size of the memory zone pointed to by pointer to have the new size size.
-(void)recycle;
Frees the receiving zone after adding the still alive allocated zones to the default zone. Currently there are no zones in libFoundation that implement this algorithm.
-(BOOL)pointerInZone:(void*)pointer;
Returns
YESif pointer points to a memory zone allocated by the receiving zone. Some zones are not able to reliably determine if the pointer is theirs or not. For exampleNSDefaultZonealways returns true since few libc malloc implementation provide the capability to identify if a pointer is valid or not.
-(void)freePointer:(void*)pointer;
If the zone was initialized to free pointers, free the memory zone pointed to by pointer. Otherwise do nothing.
-(void)setName:(NSString*)name;
Set the name of the receiving zone.
-(NSString*)name;
Return the name of the receiving zone.
-(BOOL)checkZone;
Checks the consistency of the memory allocated by the zone. Some classes, notably
NSAllocDebugZone, when you request memory from them, they allocate more memory that is marked in a special way. In-checkZonethey check if the marked zones are altered in which case they output an error message.
Go to the first, previous, next, last section, table of contents.