12

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?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Orbiting Eden
  • 1,522
  • 13
  • 16
  • 2
    https://bugs.webkit.org/show_bug.cgi?id=76225 – gman Jul 02 '12 at 16:30
  • @gman: if you answer the question, I'll give you the credit. Synopsis: WebGL uses a context that is preserved by domain and tab, irrelevant of specific page (refresh). As a result, any memory allocated to the WebGL rendering is not released for garbage collection until the user navigates away from the base domain or closes the tab. A possible fix would be to add an exit button to the application that does a quick redirect to a new domain that redirects right back. – Orbiting Eden Jul 11 '12 at 20:20
  • The bug will be fixed any day now so hopefully there will be no need for workarounds soon. There's actually a test for this in the webgl conformance tests (https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/sdk/tests/conformance/context/context-creation-and-destruction.html) – gman Jul 12 '12 at 17:35
  • My webgl behaving the same way on page refresh is not releasing the memory. (https://softwareengineering.stackexchange.com/questions/389264/do-page-reload-refresh-dont-release-the-memory-and-force-garbage-collecot-to-ru) – Muhammad Faizan Khan Mar 27 '19 at 06:15
  • Same here, refreshing the page is still not clearing the memory used up by the process. I'm also using webGL. – skiss Mar 13 '23 at 09:51

1 Answers1

2

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.

jjxtra
  • 20,415
  • 16
  • 100
  • 140
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • That is supposed to be true during the page session. However, the rule of thumb is that a page refresh should do the following: remove all nodes, orphan all variables and then force a garbage collection which should gather all those recently abandoned objects and variables and purge them from memory. Regardless, by your theory as the computer starts to run out of memory, garbage collection should collect all of those unused objects and dispose of them. But my computer just grinds to a halt instead! – Orbiting Eden Jul 02 '12 at 00:20
  • @OrbitingEden: If the memory is not collected when needed, then it's most likely an actual memory leak. The garbage collector should kick in when you run low. – Guffa Jul 02 '12 at 00:32
  • 4
    Then I guess the question is better put: How can a javascript memory leak pervade across page refreshes and navigations? That is impossible, right? – Orbiting Eden Jul 02 '12 at 00:38
  • 2
    Did you ever find an answer to this,? I have a similar issue with webgl and gpu memory. It stacks with every refresh. – Hobbes Jul 25 '13 at 05:58
  • @Hobbes did you find the solution? I am also facing the same problem that my webgl page is not release memory on page reload/refresh. – Muhammad Faizan Khan Mar 27 '19 at 05:52
  • Please consider this link https://softwareengineering.stackexchange.com/questions/389264/do-page-reload-refresh-dont-release-the-memory-and-force-garbage-collecot-to-ru – Muhammad Faizan Khan Mar 27 '19 at 05:53
  • 2
    @Muhammad Faizan Khan Seems fine for me now. Chrome r73. Also, I noticed that having the browser dev console open is just begging for memory not to be released. – Hobbes Mar 29 '19 at 18:54