UIWebView Javascript garbage collection with THREE.js plots

I am developing a game with THREE.js that will run inside a UIWebView inside an iOS8 app.

I have profiled this application in Chrome developer tools and ensured that there are no memory leaks - that is, memory usage reaches a certain value and remains constant.

Running this application in a UIWebView, however, shows that memory usage grows over time, as if there were no garbage collection at all.

I have searched the web but cannot definitively determine if the iOS8 UIWebView has garbage collection or not. Some articles seem to suggest that this is the case and some do not. If so, how can I cause it?

The only solution I can imagine at this time is if garbage collection periodically does not kill / free the UIWebView and does not recreate / restart the application (game on the menu screen).

UPDATE:

After spending a few more days looking for leaks, I found:

Disabling UIWebView doesn't work - the system never frees up everything (even with all suggested hacks) and memory issues.

I still don't know if UIWebView has garbage collection / garbage collection - the Profile / Instruments pane seems to suggest, but it doesn't, but memory usage rarely happens. Common sense tells me that some sort of garbage collection should take place because all temporary objects in the code and things out of scope are cleaned up.

My THREE.js objects apparently never get collected, but this could be due to THREE.js's own issues of having to manually dispose of resources (to free up any GL related handles, etc.)

There are cryptic leaks related to .bind (this) - example setTimeout (object.func.bind (object), 100) - apparently never clean up the function after sending the timeout - so I end up pre-binding and storing this as var ... The same goes for any even handlers passed to jQuery.

My 2 game scene (menu scene and game scene), I ended up rewriting in such a way that both scenes remain in memory (never deleted). Any objects and models that I create in the game, instead of relying on GC to get the collected data, are recycled instead. When objects are removed from the scene, they are placed in a pool of objects of the same type to be reinitialized and re-added when such an object is needed again in the scene. It seemed like overkill at first, but the advantage is no memory leaks (objects remain allocated) and faster creation / addition to the scene.

+3


source to share


2 answers


Memory grows because some resources are cached in memory due to the HTTP caching strategy. So if your memory doesn't grow indefinitely, don't worry about it.



+1


source


What you are seeing is probably a bug in iOS8 where the garbage collector never frees memory. I wrote about it here: PhoneGap using more memory in iOS8 than iOS7



If you can file the bug with Apple, we can install that on the next OS version.

+1


source







All Articles