browser refresh does not do garbage collection

2020-06-16 01:59发布

问题:

I have found this on all browsers tested - IE, Firefox, Chrome and Safari on Window sand Safari on Apple.

Allegedly, a browser refresh, back button or forward link should dump the browser nodes and javascript variables and objects, etc. This appears to not be the case for WebGL. I first noticed it when developing a complex WebGL application that requires about 100MB to 200MB of memory. While developing, I have to do a lot of refreshes and my computer would start to slow down and freeze after 5-10 refreshes.

After some research I realized that this shouldn't be. The accepted solution out of a memory leak is to refresh the page which should release all javascript objects and variables and dom nodes. But take a look at the following images:

So what's the deal here? On small apps it isn't noticed, but for large WebGL apps like mine (orbitingeden.com) this is a real issue and my users are going to think the software is even more of a resource hog than it really is. The following image shows these refreshes gobbling up all of my available memory, so garbage collection is not working and / or JS and DOM objects are not being released:


(source: orbitingeden.com)

Does someone know of a trick to force the browser to do a true dump of memory? Why is all the documentation out there wrong?

回答1:

One of the points with garbage collection is that the objects are not cleaned up immediately they get unused. The garbage collector can determine for iteself when it's most convenient to do collections.

It's normal for a garbage collected system tp leave some unused objects in the heap, as long as there is plenty of memory to use. A computer doesn't run any faster from having a lot of unused memory.