1

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.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
user420589
  • 59
  • 2
  • 5

2 Answers2

1

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'...");
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
derjanb
  • 1,020
  • 10
  • 13
  • It's great that you fixed a memory leak (+1) in your own code. But part of this answer contains wrong information (-1; See the answer I reference). Not sure I like the "flickering tabs" idea either. – Brock Adams Apr 23 '13 at 00:08
  • Also, please modify your website so that direct links, to the changes you reference, open a page showing that change already and scrolled to it. – Brock Adams Apr 23 '13 at 00:09
0

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.

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295