Yes β if you have a memory address from a leak report, LLDB can tell you what object it points to:
memory read --format x --size 8 --count 1 0xADDRESS
Or better:
expr -O -- (id)0xADDRESS
If it's a Swift object:
expr -l Swift -- unsafeBitCast(0xADDRESS, to: MyType.self)
This can show properties and type name if symbols are available.
No β LLDB cannot directly tell you what is retaining an object. Swift and Objective-C donβt expose full retain graph inspection APIs via LLDB.
But you can:
- Set a watchpoint on the retain count (on Obj-C
isa
or Swift reference count internals). - Use
po
orexpr
to print suspected references (e.g., arrays, dictionaries, closures).
leaks PID
- Shows leaked memory regions and backtraces
- Often identifies leaked Swift/Obj-C objects by class/type
- Best run from Terminal outside LLDB while app is paused
You can also run leaks
from within LLDB:
process detach
! leaks PID
process attach --pid PID
heap PID
- Shows live allocations grouped by type
- Helpful to estimate how many instances of a type exist
- Can show where a large group of leaked instances were allocated
malloc_history PID 0xADDRESS
- Shows allocation stack trace of the specific memory address
- Essential to know where it was allocated
-
Pause the app (breakpoint or attach)
-
Run
leaks PID
orheap PID
in Terminal -
Copy a suspicious memory address
-
In LLDB:
expr -O -- (id)0xADDRESS
or
expr -l Swift -- unsafeBitCast(0xADDRESS, to: SuspectedType.self)
-
Use
malloc_history
to trace allocation site:malloc_history PID 0xADDRESS
-
Inspect references in LLDB by printing containers or static properties
- LLDB can inspect memory and state but not ownership or retain graphs
- Swift ARC doesnβt expose retain counts or owners
- Instruments or Xcode's Memory Graph is better for visualizing retain cycles