I am working on design of an android social application. this app look like telegram. it has two activity. on first activity, list of group is shown. when user clicked on a group, list of group message is shown on second activity. message can contain text,photo,video or sticker. I use a RecyclerView to show list of message.
sometimes when user is working on second activity, out of memory error is happened.
when a photo message must be shown, the bitmap of before photo message is recycled and set to null, then i show the new photo message on Imageview.
to show a sticker message, by using a library, the bitmap is created from sticker file, and shown on ImageView. the process of creating bitmap, get noticeable amount of memory. i asked about sticker problem in this post
when user is working on message list activity, memory diagram look like below image.
when the user reads its group messages and come back to first activity, the second activity is destroyed but memory of second activity is not freed. when the user clicks on another group, second activity started again and it use another part of free memory. repeating this action cause consuming more and more memory and finally end of application working because of "out of memory".
when the user closes the app,the memory is not freed. if the user opens the app again, free part of memory is used to show application. multiple opening of app cause out of memory.
what should i do? how to free heap memory when an activity is destroyed or the app is closed.
the size of images (50px * 90px) and stickers (20kb - 50kb) is small.
sorry if i am poor in English. i hope that someone can help me.