Jump to content

User:Mdaniels5757/chromeAutoGarbageCollect.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mdaniels5757 (talk | contribs) at 22:32, 20 July 2020 (redo). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/**
 * @file This script just runs Chrome's garbage collector periodically.
 * (every wait_ms milliseconds, to be exact).
 * Made because there's some sort of memory leak in one script/gadget or another
 * and I can't be bothered to figure out which.
 * The relevant Chrome flag must be enabled for this to work.
 * 
 * @copyright Copyright 2020 Michael Daniels (Wikipedia User:Mdaniels5757)
 * @license Your choice of CC-BY-SA-3.0 (https://creativecommons.org/licenses/by-sa/3.0/legalcode) and Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
 */ 

if (wait_ms === null) var wait_ms = 61000;

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

function runGC() {
	window.gc();
	
	sleep(wait_ms).then(() => {
		runGC();
	});
}

runGC();