There are two activities in my application: A and B.
Activity A:
It has a list that briefly displays information about the item. When an item is clicked on A, it loads action B.
Activity B:
It has two web views and several lists. At the top of the activity is the title of the web view. At the bottom of the activity there is a host node, it hosts the second web view on the first tab, and on the remaining tab each node has a list view.
Problem:
When the user moves from A to B, the heap size increases significantly. Even after I go back from B to A, the heap size remains unchanged. Even the byte does not decrease; in fact, it sometimes increases. Yes, due to these web views. I read about web view memory leak on SO and other sites. I followed the approach mentioned here
- Dynamically added webview inside container [RelativeLayout]. Remote webview in onDestroy actions
- Subclass Web Browsing suggested in SO article
- Cleared web browsing cache every time, etc.
No matter what the size of the heap does not return to what it was before moving to B.
Really evaluate if anyone can lead me to a possible fix.
Note:
I already read this and followed this issue on SO. Memory leak in WebView
Edit:
I tried without browsing the web in B and the heap size increase is very slightly less than about 0.5 MB, but with web browsing it adds up to 4-5 MB
Logs with heap sizes (obtained by next sentence here )
onCreate B debug.heap native: allocated 4.11MB of 4.17MB (0.01MB free) in [] debug.memory: allocated: 12.00MB of 96.00MB (1.00MB free) onDestroy B debug.heap native: allocated 8.66MB of 10.08MB (0.48MB free) in [] debug.memory: allocated: 12.00MB of 96.00MB (1.00MB free) on Resume A debug.heap native: allocated 7.94MB of 10.08MB (1.32MB free) in [] debug.memory: allocated: 12.00MB of 96.00MB (0.00MB free)
I cross-checked the numbers by taking a bunch of dumps before and after B was launched and destroyed, the heap size is pretty close to the one I get in the logs
source share