user420589
user420589

Reputation: 59

Clear browser tab RAM usage from/for Tampermonkey?

I am looking for a solution for injected javascript with Tampermonkey for Chrome, where every reload of page would clear usage of RAM and not increase it.

I am making tests of Injected scripts with Chrome Developer Tools->Timeline. Every time I reload the page, RAM usage increases.

My javascript includes few jQuery AJAX calls, and few lines of code.

I tried every possible javascript reload function, but none gives me the result I want.

So If anyone has idea, how to solve that, I would be really thankful.

Upvotes: 1

Views: 3043

Answers (2)

derjanb
derjanb

Reputation: 1080

Update:
I've fixed a memory leak in Tampermonkey that caused some data to stay in memory even after a page reload. So maybe your problem is fixed now.



Select another tab and wait some seconds. There is no other way to trigger the garbage collection.

Maybe you can use this magic to fake a full reload:

// ==UserScript==
// @name       fake reload
// @namespace  http://use.i.E.your.homepage/
// @version    0.1
// @description  enter something useful
// @match      http://tampermonkey.net/empty.html
// @copyright  2012+, You
// ==/UserScript==

function fake_reload() {
    console.log("...now");
    GM_openInTab(window.location.href, {active: false, insert: true});
    // close the current window some ms later to allow the insert magic to detect this' tab position
    window.setTimeout(window.close, 1);
}
window.setTimeout(fake_reload, 3000);
console.log("run 'fake reload'...");

Upvotes: 2

Brock Adams
Brock Adams

Reputation: 93543

You probably have a memory leak in the script code. See this answer for ideas about plugging such leaks.

Normally, you can't clear RAM from javascript, by design. But, if you're hardcore about finding and plugging the memory leaks in the userscript (and maybe on the target page), you can grab/build a debug version of Chrome and then see this answer for how to allow javascript to force garbage collection.

Upvotes: 0

Related Questions