My site crashes in the browser due to low memory on iOS. I'm repeating some action which consumes memory. After several attempts, the browser crashes. However, when I tested the same site on my desktop using Chrome by using timelime from dev tools:
- Perform the same action
- Collect garbage
- All additionally allocated memory is collected.
Why does the browser crash if there are no memory leaks? Is there a way to force garbage collection?
Below is the best resource (with benchmarks) which I have ever come across, that explains it: http://sealedabstract.com/rants/why-mobile-web-apps-are-slow/
I hit those performance hurdles a few weeks back, and please note that iOS does not have any default garbage collection (the article explains why). It is the responsibility of the app (in this case, the browser app). You cannot collect garbage via your web app. A small tip while optimizing your website for iOS (to prevent crashes): avoid CSS transations.
Though I would recommend that you grab a cup of coffee and read the complete article, but I'll paste the summary below:
Know iOS Resource Limits
Your webpage performing well on the desktop is no guarantee that it will perform well on iOS.
1.Keep in mind that iOS uses
to connect to the Internet.
2.You need to minimize the size of your webpage. Including
which adversely affects your site’s performance on iOS.
3.Because of the memory available on iOS, there are limits on the number of resources it can process:
4.The maximum size for a canvas element is
5.JavaScript execution time
6.The maximum number of documents that can be open at once is
Please refer Developing Web Content for Safari-Apple Documentation for more info.
Garbage Collection
Mobile safari javascript implementation doesn't have any command like CollectGarbage() in internet explorer for garbage collection.
Its really a bad practice to trigger garbage collection.What we should be doing is to write codes that doesn't leak memory.
Plese refer Memory management in Javascript