Hi!
I have written a gnome shell extension that displays system infos (
http://github.com/paradoxxxzero/gnome-shell-system-monitor-applet).
I am having a hard time figuring out why when my extension is running, gnome
shell memory usage is going crazy.
So I isolated this script that runs with gjs and uses a lot of memory:
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
const GLib = imports.gi.GLib;
const Mainloop = imports.mainloop;
const Lang = imports.lang;
function Mem_State() {
this._init();
}
Mem_State.prototype = {
_init: function() {
this.update();
},
update: function() {
let meminfo_lines =
GLib.file_get_contents('/proc/meminfo')[1].split("\n");
for(let i = 0 ; i < meminfo_lines.length ; i++) {
let line = meminfo_lines[i].replace(/ +/g, " ").split(" ");
switch(line[0]) {
case "MemFree:":
this.mem_free = line[1];
break;
}
}
}
};
function SystemMonitor() {
this._init.apply(this, arguments);
}
SystemMonitor.prototype = {
memory: {
state: new Mem_State(),
update: function () {
this.memory.state.update();
log("Free mem: " + this.memory.state.mem_free + " kB");
}
},
_init: function() {
let n = 0;
this.timeout = Mainloop.timeout_add(
5,
Lang.bind(this, function () {
Lang.bind(this, this.memory.update)();
if(n++ > 100000)
Mainloop.quit('testMainloop');
return true;
}));
}
};
new SystemMonitor();
Mainloop.run('testMainloop');
log('done');
If somebody can tell me what I am doing wrong, I would be very grateful.
Best regards
--
Florian Mounier
_______________________________________________
javascript-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/javascript-list