The web view takes a lot of memory, how could I reduce the memory usage?

UniWebView is using system web view for showing your content, so the memory usage should be the same as you use the system web view in a native app. In fact, either the UIWebView control in iOS or the WebView control in Android does not perform very well in memory usage. They will both cache some assets for later use or maybe just due to internal bugs. There is little UniWebView could do on it. But I just want to give you some tips on how to reduce the memory usage as much as possible.

  1. You have to destroy the web view component correctly. Please make sure to call destroy on the UniWebView component. It will remove the web view from native code and try to clean the memory. At the same time, you should not keep any reference to the web view component in you Unity side as well. It is critical and a must-do since the memory will never be released unless you destroy the component. You can find the correct way on how to destroy the web view in the demo script in our package.
  2. Before you destroy the component, you could try to load an empty page (about:blank). It will force the web view to release some assets in current web page (especially for videos and audios). Sometimes it could help to reduce the memory pressure.
  3. You could try to call CleanCache on the web view, which will clean the url and data cache for you. But there is a side-effect that it will also make current cached content invalid. It means your users have to request the resources again even the site has a cache strategy.
  4. In fact most of taken memory could be returned to system when a memory warning from system is received. If you did step 1 correctly, it should not be a big problem on the memory usage.
Have more questions? Submit a request


Please sign in to leave a comment.
Powered by Zendesk