Xcode ToolsMidMCQ

What is the Address Sanitizer?

Test your knowledge:

Explanation & Code

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.

Rate your understanding:

Ready to practice more Xcode Tools?

Test yourself with our interactive quiz mode or browse all curated questions for this topic.