Clean GeoGebra-web-evaluator used memory

yahone chow
1 min readOct 26, 2021

There was a weird Bug annoying me for weeks, since i embed GeoGebra(GGB)-evaluator in a web app.

When user invoked GGB-related components in web app, GGB keep running and using a ton of cpu and memory, if you keep tab’s opening, may lead several issues like huge cpu using, high temperature, browser’s tab crash, cookie lost and so forth.

Step one, is to remove all doms created by GGB.

// 1.remove injected dom by applet// 2.remove GGB dom
let webFrame = document.querySelector('#web');
webFrame && webFrame.remove();

Step two, remove all related properties under the window object

// best practice
// record all key before invoke GGB
var obj1 = {};
for(var i in window){
if(window.hasOwnProperty(i)){
obj1[i] = i
}
}
// then, after invoked GGB
// store keys in another variable
var obj2 = {};
for(var i in window){
if(window.hasOwnProperty(i)){
obj2[i] = i
}
}
// compare
var list = []
for(let i in obj2){
if(!obj1[i]){
console.log(i)
}
}
// my result
let list = [
'isRenderGGBElementEnabled',
'scriptLoadStarted',
'html5AppletsToProcess',
'ggbHTML5LoadedCodebaseIsWebSimple',
'ggbHTML5LoadedCodebaseVersion',
'ggbHTML5LoadedScript',
'GGBApplet',
'GGBAppletUtils',
'web3d',
'webSimple',
'web',
'__gwt_activeModules',
'__gwt_getMetaProperty',
'__gwt_isKnownPropertyValue',
'__gwt_stylesLoaded',
'renderGGBElementReady',
'goog',
'java',
'org',
'renderGGBElement',
'copyGraphicsToClipboard',
'isCopyImageToClipboardAvailable',
'fflate',
'base64Util',
'getHiddenProp',
'isHidden',
'visibilityEventMain',
'domvas',
'__GGB__keysVar',
'XMLUtil',
'GwtPotentialElementShim',
'ggbApplet',
'__JLM2_GWT_FONTS__',
];

Then you can delete all keys

list.map(k => {
// for GGB internal circular reference
// using try-catch
try{
delete window[k]
} catch(e){
// do sth
}
})

For other app kind (e.g. calculator), you can did it in the same way (check dom-tree and compare global variables )

--

--