Search code examples
androidperformanceandroid-memory

setImageResource and memory leak


In my Activity, I use imageView.setImageResource(R.drawable.image_name); about 8 times for different views.

I kept opening and closing the activity repeatedly and I notice the app is getting laggy. I am wondering if this is related to memory leak? Is it because of that piece of code?


Solution

  • You should recycle() all your bitmaps when done using them. If you want to destroy them when activity is finish()ed, you can override onDestroy to destroy all bitmaps