INSTRUMENTS: LEAKS
Trevor Brown
Triangle CocoaHeads
September 2012
Slide 2
Slide 2 text
What are leaks?
How can we detect them?
How can we prevent them?
Q&A
Resources
Slide 3
Slide 3 text
Memory that...
has been consumed (allocated),
is no longer needed,
but cannot be returned to the OS for reuse
or accessed by the program that allocated it.
Is there a problem with that?
Waste of resources
Slowdown (unresponsive)
Unexpected shutdown by OS
WHAT ARE LEAKS?
(and why they’re bad)
Slide 4
Slide 4 text
HOW CAN WE
DETECT LEAKS?
Static Analyzer (Xcode)
Instruments
Code review
Slide 5
Slide 5 text
Launch your app
with the profiler
Slide 6
Slide 6 text
No content
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
No content
Slide 9
Slide 9 text
No content
Slide 10
Slide 10 text
No content
Slide 11
Slide 11 text
Random audience member:
“Thanks for the total waste of time, Trevor.
I use ARC. Like, all the time. Wow...
Um, beer, anyone?”
Slide 12
Slide 12 text
RETAIN CYCLE
Slide 13
Slide 13 text
Object A Object B
RETAIN CYCLE
Slide 14
Slide 14 text
No content
Slide 15
Slide 15 text
LEAK PREVENTION
Use ARC (convert)
Avoid retain cycles (no strong-strong relationships)
Handle low-memory warnings from the OS
Run the static analyzer