Problem description: use Bitmap display images in the project, the app starts loading no problem, but after repeated opening and closing the page many times, the picture shows, through debugging found BitmaoFactory. DecodeFile parse Bitmap () method returns a null value, the incoming parameters can be determined without any problems.

Cause: BItmap resources occupy a large amount of memory. The occupied memory is not released after the page exits, but still occupies a large amount of memory. New BItmap objects will be created each time when the page is opened repeatedly, resulting in insufficient memory and failure in BItmap parsing.

My solution: When exiting the interface, I actively call bitmap.recycle() to release bitmap memory.

private fun clearAdapter(){ val faceList = mAdapter? . AllItems // Bitmap resources occupy a large amount of memory, proactively release memory faceList? .forEach { it -> it.bitmap? .recycle() } }Copy the code