Uiwebview svg rendering causes memory pressure (and application crash)

I am working on an “interactive map” similar to this example . I needed to enlarge the map and still get a clean illustration, so the map drawing is done in svg (it was actually created in Illustrator and then saved as an svg file).

In the application, I create a UIWebView and load the html containing svg. The HTML file is the package resource in the application, so there is no network delay. There are stupid forms that, when clicked on, take you to another map (another html page with svg image).

One of svg is quite large (~ 5.8MB). When I boot, I get a warning “Memory pressure”, after which it crashes. The tools show virtual memory at 298.71 MB and real memory at 149.10 MB during a crash.

I already simplified the drawing (I took some details), and I also used @Peter Collingridge svg optimizer .

How can I optimize memory usage so that it does not work?

+6
source share
1 answer

I solved my problem:

  • I created a webview in my viewWillAppear: method before calling [super viewWillAppear:animated] . I originally did this because I have a superclass that creates common elements for all the different maps that I have, and so the elements appeared in the correct order. Now the super call is done first and foremost, and I bring the elements to the forefront.

  • Now I set my webview to zero before creating and clicking on a different map (so another webview with different content).

  • The first web view was created by a storyboard. Now everything is done in code.

  • Map drawings were simplified, so the files are smaller. (Less details)

A memory report shows that memory usage is now around 81.9 MB (16.2% of the available memory on the 5th generation iPod Touch).

It seemed strange to me that I had a warning about memory pressure with a (rather) small svg file. In addition, the indicator showed a percentage that never exceeded 50%. I did not consider the JS mechanism and restrictions on access to web browsing. (It is said that the Javascript engine gets full power in iOS 8, as reported here ). (I could not find the official documentation on memory limitations, perhaps because it seems to be different from device to device. See this answer .)

After all, page loading still lasts on my iPhone 4 or my 5th generation iPod Touch, but it works. If you want to offer the best way to reach such a card, you can do it.

+1
source

All Articles