Integration Testing for Memory Leaks
Article Summary
Matthew Healy from SoundCloud reveals how a single integration test can catch memory leaks across an entire VIPER module. Unit tests alone won't save you from the sneaky leaks hiding in object interactions.
The SoundCloud iOS team faced a challenge: their VIPER architecture created multiple potential leak points (delegates, observers, closures) that were tedious to unit test individually. They needed a scalable approach to catch memory leaks without writing hundreds of tests.
Key Takeaways
- Weak delegates aren't the only culprit: closures capturing self can leak too
- One integration test covers entire VIPER module vs dozens of unit tests
- Internal makeAndExpose() method exposes module components for testing only
- Test holds weak references to components, drops view, asserts everything deallocates
- Approach immediately caught a real memory leak they didn't know existed
Critical Insight
Integration tests that verify entire module deallocation provide maximum leak coverage with minimal test code, catching bugs that slip past unit tests.