Skip to content

How To Debug iOS Memoery Issues

Guard Malloc

Guard Malloc is a special version of the malloc library (libgmalloc) that replaces the standard library during debugging.

It places separate memory allocations on different virtual memory pages and then deletes the entire page when the memory is freed.

Subsequent attempts to access the deallocated memory cause an immediate memory exception rather than a blind access into memory that might now hold other data.

Malloc Scribble

After enable Malloc Scribble:

  • free sets each byte of every released block to the value 0x55.
  • malloc sets each byte of a newly allocated block to the value 0xAA.

These values are defined in libmalloc-372.30.4/src/base.h.

c
#define SCRIBBLE_BYTE 0xaa /* allocated scribble */
#define SCRABBLE_BYTE 0x55 /* free()'d scribble */
#define SCRUBBLE_BYTE 0xdd /* madvise(..., MADV_FREE) scriblle */

Malloc Guard Edges

If set, malloc adds guard pages before and after large allocations.

Zombie Objects

Malloc Stack Logging

References