0

My application has multiple WebViews that stack on top of each other when the user goes to a new page. (This is done so that, when the user clicks the Back button, the current WebView simply slides away and reveals the previous WebView underneath, with no need to reload the page)

The problem is that, with more and more WebViews that are instantiated, the app's memory usage increases linearly, until it runs out of memory and crashes.

Now, I looked at the stock Android Browser app, and I see that I'm able to open a great number of tabs (each of which presumably has its own WebView?), and yet this barely makes a dent in its heap usage. How does the Browser do it?

Dmitry Brant
  • 7,612
  • 2
  • 29
  • 47
  • Because it caches those pages and simply reloads the cached files. – Timothy Frisch May 15 '14 at 20:14
  • you can read about caching here: http://stackoverflow.com/questions/9128952/caching-in-android-webview – Timothy Frisch May 15 '14 at 20:15
  • @Tukajo I don't think that's the case. The Browser doesn't do any network access when switching between tabs. – Dmitry Brant May 15 '14 at 20:16
  • Are you saying you have say, 50 tabs on the browser each with a loaded website? If that's the case it's because the browser has code that allows for only one webview to be viewed at once. I.E. it stores pertinent information of each tab (most likely a cached file) and then when that tab is active it loads the corresponding cached file. – Timothy Frisch May 15 '14 at 20:18
  • While the others are simply pushed to caches and not rendered/active. Where your recreation of tons of webviews is not only taxing due to the amount of webviews you are instantiating; but also taxing because you are actively running each webview behind it. – Timothy Frisch May 15 '14 at 20:19
  • Much like `Fragment`s in Android, you don't simply "add" a bunch of fragments on top of eachother; but instead you store relevant data for the fragment and have them `Replace` eachother. – Timothy Frisch May 15 '14 at 20:20
  • Also; a browser doesn't need to do "Network Access" to reload a cached file... that is literally what a cached file is - a locally stored instance of the webpage. – Timothy Frisch May 15 '14 at 20:21
  • @Tukajo Sorry, what I meant to say is that the Browser doesn't seem to do any "reloading" of the page when switching tabs. It's extremely fast; much faster than when I try to load different pages on a single WebView, even with caching enabled. Which leads me to believe that it's using multiple WebViews. – Dmitry Brant May 15 '14 at 20:23
  • It's possible that it uses multiple `WebView`s contained in `Fragment`s... – Timothy Frisch May 15 '14 at 20:24
  • @DmitryBrant Did you resolved this issue. As I got stuck with this. – Nitin Aug 09 '18 at 00:20

0 Answers0