Skip to content

Instantly share code, notes, and snippets.

@jandrieu
Created July 25, 2013 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jandrieu/6083874 to your computer and use it in GitHub Desktop.
Save jandrieu/6083874 to your computer and use it in GitHub Desktop.
Leaker.js memory leak generator using dbus-native
#!/usr/local/bin/node
var dbus = require('dbus-native');
var memwatch = require('memwatch');
var bus;
bus = dbus.sessionBus({socket: '/var/run/dbus/system_bus_socket'});
bus.connection.on('error',function(err){
console.log("Error on dbus connection: " +JSON.stringify(err,null,2));
})
function leak() {
bus.invoke({
type: dbus.messageType.methodCall,
path:'/org/freedesktop/DBus',
destination: 'org.freedesktop.DBus',
member: "ListNames",
}, function invokeCallback(err,res){
if(err) {
console.log("Error invoking:" + err);
}
});
};
memwatch.on('leak', function memwatchLeak(info) {
console.log('*********************** LEAK *****:'+JSON.stringify(info));
});
setInterval(leak,10);
@sidorares
Copy link

FYI - there is a bunch of std method helpers in bus object, for example your code could be as

var dbus = require('dbus-native');
var memwatch = require('memwatch');
bus = dbus.sessionBus();
function leak() {
  bus.listNames(function(err, names) {
    if(err) {
      console.log("Error invoking:" + err);
    }
    leak();
  });
}

memwatch.on('leak', function memwatchLeak(info) { 
  console.log('*********************** LEAK *****:'+JSON.stringify(info));
});

leak();

My results:

* LEAK :{"start":"2013-07-26T00:36:20.000Z","end":"2013-07-26T00:36:25.000Z","growth":3750856,"reason":"heap growth over 5 consecutive GCs (5s) - -2147483648 bytes/hr"}
***
* LEAK :{"start":"2013-07-26T00:36:26.000Z","end":"2013-07-26T00:36:30.000Z","growth":3291720,"reason":"heap growth over 5 consecutive GCs (4s) - -2147483648 bytes/hr"}
***
* LEAK :{"start":"2013-07-26T00:36:40.000Z","end":"2013-07-26T00:36:50.000Z","growth":6018444,"reason":"heap growth over 5 consecutive GCs (10s) - -2147483648 bytes/hr"}
***
* LEAK :{"start":"2013-07-26T00:36:53.000Z","end":"2013-07-26T00:37:06.000Z","growth":8297544,"reason":"heap growth over 5 consecutive GCs (13s) - -2147483648 bytes/hr"}
***
* LEAK :{"start":"2013-07-26T00:38:10.000Z","end":"2013-07-26T00:38:23.000Z","growth":6122960,"reason":"heap growth over 5 consecutive GCs (13s) - 1617.04 mb/hr"}
***
* LEAK :{"start":"2013-07-26T00:38:27.000Z","end":"2013-07-26T00:38:47.000Z","growth":11290784,"reason":"heap growth over 5 consecutive GCs (20s) - 1938.19 mb/hr"}
***
* LEAK :{"start":"2013-07-26T00:38:53.000Z","end":"2013-07-26T00:39:20.000Z","growth":13045836,"reason":"heap growth over 5 consecutive GCs (27s) - 1658.86 mb/hr"}
***
* LEAK :{"start":"2013-07-26T00:39:27.000Z","end":"2013-07-26T00:40:16.000Z","growth":26602412,"reason":"heap growth over 5 consecutive GCs (49s) - 1863.92 mb/hr"}
***
******* LEAK *****:{"start":"2013-07-26T00:40:29.000Z","end":"2013-07-26T00:41:31.000Z","growth":37480108,"reason":"heap growth over 5 consecutive GCs (1m 2s) - -2147483648 bytes/hr"}

@jpatoyon
Copy link

jpatoyon commented Aug 5, 2013

Any luck tracking down where the leak is happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment