YUNOVA · Android Development
Module 12: Performance and testing
Memory leaks and LeakCanary
Key points
- A leak happens when an object outlives its use, such as an Activity held by a static field.
- LeakCanary watches destroyed objects in debug builds and reports leaks with a trace.
- Clear listeners and avoid holding Context in long-lived objects.
Android Studio Profiler
Key points
- The Profiler shows CPU, memory and energy use of a running app.
- A CPU recording shows which methods take time on each thread.
- A heap dump shows which objects are using memory.
UI tests with Espresso and Compose testing
Key points
- Espresso finds Views, performs actions and checks the result.
- Compose tests use a test rule and find nodes by text, tag or semantics.
- UI tests run on a device or emulator as instrumented tests.
Paging 3 for large lists
Key points
- Paging 3 loads a large list in pages as the user scrolls.
- A PagingSource loads one page; the Pager turns it into a Flow of PagingData.
- In Compose, collectAsLazyPagingItems feeds a LazyColumn.