Search code examples
androidmemorybitmapout-of-memoryscrollview

Why does scrolling a scrollview increase memory usage a lot?


I have a acrollview which contains maybe 15 rows in imageview (own special listview). Each row contains text and cross bitmap.

When I first create the scrollview there is almost no memory usage, but at the moment I touch it to scroll, memory usage is increased by ~2 MB.

This tends to make GC run which makes scrolling very choppy.

I'm reusing the views, so this can not be it. Any ideas?

I set bitmap into imageview immediately, not from internet, I generated bitmap from user data. sometimes 25 or more lines.

Can I somehow clear memoryusages? and Init with need value actualy?

I thing so code it's unnecessary, but If you want/need write.

If I scrool too long app crashed on outOfmemory error

===================EDIT===================================

I I found out I generated new image on every touch (as it's the same)..

now increase less, but increase.


Solution

  • A best practice in Android for such cases would be to use a Recycler View with an Adapter. This will keep your memory in check.

    https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html

    Also check out this great video from udacity https://www.youtube.com/watch?v=-VPM6ICgCk8