Profiling your app with Android Studio

If we can reduce the frequency of the invocations of BitmapFactory.decodeResource(), we can avoid the need for additional memory allocation and therefore decrease the occurrence of Garbage Collection.This is an improved version of RecyclerViewAdapter that creates bitmap instances only once, caches them, and reuses these bitmaps for the imageView in theonBindViewHolder() method. Any other unnecessary memory allocation is avoided. Let’s take a look at the memory graph after the improvement.We see a flat memory usage graph, and there’s only one allocation for a byte array, and its size is negligible. Also, the application can now scroll smoothly without any sluggishness. We’ve just fixed our memory issue :)Smooth RecyclerViewSummaryI hope this article has given you an idea of how to use the profiling tool to analyze a performance issue..Always pay attention to memory usage in your application and avoid allocating unnecessary memory resources..Just remember, the goal is to make your memory usage graph as flat as possible.Editor’s Note: Looking to clean up your mobile development processes?.Here are a few more helpful Heartbeat resources to help get you started:Artificial Intelligence in Mobile App Testing with Bitbar’s AI TestbotAn Introduction to Kotlin on Android — Concision and SafetyHow to Upload Images in a React Native AppWant to join the conversation surrounding all things mobile and ML?.Sign up for Heartbeat’s Slack group. More details

Leave a Reply