Challenge
Throughout the tutorial you’ve used an in memory repository to get and save the logs. Therefore the logs are always deleted between sessions of the app.
Open MainApplication.kt and you’ll see a commented line to use a SharedPreferences repository implementation that permanently saves the logs. Uncomment this line and comment or delete the one you’ve been using.
Build and profile the app to see it’s creating many TripLog
instances. For example, after adding five logs you’ll see the app actually allocated eleven instances. As a challenge, try to refactor SharedPreferencesRepositoryImpl
to minimize the quantity of allocations.
You can find the completed challenge in the same download from the Download materials button found at the top or bottom of this tutorial.
Where To Go From Here?
You can download the completed project using the Download materials button at the top or bottom of the tutorial.
Congratulations! You now know how to:
- Use the Android Profiler to analyze memory.
- Use Heap Dumps to identify which classes allocate large amounts of memory.
- Perform Allocation Tracking over time to understand when the app allocates or deallocates objects and also to know where in your code the allocation is happening.
If you want to learn more about the subject, please check the following references:
I hope you enjoyed this introduction to Android Memory Profiler tutorial. If you have any questions, comments or awesome modifications to this project app please join the forum discussion and comment below!