Why does heap size keep increasing?

2019-09-11 06:58发布

问题:

I have an application that has a lot of ripple effects and animations.

I tried going back and forth multiple screens, and also spam clicking buttons.

I noticed that the heap size continuously goes up even though some screens have already been closed.

When I checked the heap dump, the class with the highest Retained heap was the android.graphics.Bitmap class and points to all of the buttons I clicked that has a Ripple Effect.

The Ripple Effects on the buttons are just simple ripples which uses ?attr/selectableItemBackgroundBorderless as the background. But it goes up by 0.3mb or 0.5mb on every click of the buttons with ripples.

回答1:

Could be a MemoryLeak of some kind. It's almost impossible to tell where is the problem without analise the code. I recommend some tests.

You could try the Leak Canary library. The lib can "watch" specifics objects and narrow the search for the leak.