How to reduce .apk mmap memory size in my android app

768 views
Skip to first unread message

jesse...@gmail.com

unread,
Jul 18, 2017, 11:01:22 AM7/18/17
to android-platform

When i never open activity with webview, I dump my app meminfo,is like: 



When i open an activity with webview, I dump my app meminfo,is like: 


When i close this activity,the .apk mmap (Pss Total and Private Clean)is still very large. I have add and remove webview dynamically and called webview.ondestroy() when activity is destroyed. Why .apk mmap remains unchanged? What the .apk mmap means? Anyone can help me, Thanks!

AppCoder

unread,
Jul 19, 2017, 11:19:08 AM7/19/17
to android-platform
The issue you are seeing is that the underlying core implementation of the webview makes and re-uses a singleton to handle the javascript/html rendering that is not exposed to the public api.  In theory, this helps performance because starting/stopping that core is expensive.  In practice it causes a bunch of oddities (like configurations/cache etc being shared across the webviews presented through the public api and persisting through their destruction.)

I don't think there is a way to get it to shut down.

The closest you could get would be to put your activity in another process and hope that process goes away when your activity exits.

See

https://developer.android.com/guide/topics/manifest/activity-element.html

and the android:process chunk, give that activity it's own unique process name.

This will put your activity in another process, and you will need to use RPC stuff to get data to/from it (so poking at static variables in a service or another activity won't work.)

jesse...@gmail.com

unread,
Jul 20, 2017, 1:51:04 PM7/20/17
to android-platform
Thanks! New process is helpful!

在 2017年7月19日星期三 UTC+8下午11:19:08,AppCoder写道:
Reply all
Reply to author
Forward
0 new messages