Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

browser refresh does not do garbage collection

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:

enter image description here
(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?

like image 297
Orbiting Eden Avatar asked Jul 01 '12 23:07

Orbiting Eden


People also ask

Can you force garbage collection in JavaScript?

As of 2019, it is not possible to explicitly or programmatically trigger garbage collection in JavaScript.

Does garbage collector clear stack memory?

Does the garbage collector sweep stack memory? No. The garbage collector does only manage heap memory. All values on the stack are expected to be needed again when the program returns to that stack frame, so they must not be collected.

What is garbage collection Web?

Garbage collection is a term used in computer programming to describe the process of finding and deleting objects which are no longer being referenced by other objects.


1 Answers

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 to 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.

like image 51
Guffa Avatar answered Oct 07 '22 00:10

Guffa