Browse Questions
  • Address Sanitizer (ASan) is a runtime tool that detects memory corruption bugs — buffer overflows, use-after-free, and invalid memory access — that would otherwise cause mysterious crashes.
  • Each feedback type has a very different responsibility — don't let them overlap.
  • A lazy property is only computed the first time it is accessed.
  • Breakpoints pause execution so you can inspect state.

Answer: Address Sanitizer (ASan) is a runtime tool that detects memory corruption bugs — buffer overflows, use-after-free, and invalid memory access — that would otherwise cause mysterious crashes.

How to enable:

  1. Edit Scheme → Run → Diagnostics
  2. Enable Address Sanitizer
  3. Optionally enable Undefined Behavior Sanitizer too

What it catches:

  • Buffer overflow (reading/writing past array bounds)
  • Use-after-free (accessing deallocated memory)
  • Use-after-return (returning pointer to stack variable)
  • Double-free

Example output:

==ERROR: AddressSanitizer: heap-buffer-overflow
READ of size 4 at 0x... thread T0
    #0 MyApp in processData() MyClass.swift:47

Note: ASan adds significant runtime overhead (~2x slower, ~3x more memory) — only enable it when hunting bugs, not for regular development.