{"action":"created","issue":{"url":"https://api.github.com/repos/OpenZWave/node-openzwave-shared/issues/59","labels_url":"https://api.github.com/repos/OpenZWave/node-openzwave-shared/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/OpenZWave/node-openzwave-shared/issues/59/comments","events_url":"https://api.github.com/repos/OpenZWave/node-openzwave-shared/issues/59/events","html_url":"https://github.com/OpenZWave/node-openzwave-shared/issues/59","id":128911893,"number":59,"title":"Memory leak with more then one instance.","user":{"login":"navstev0","id":916489,"avatar_url":"https://avatars.githubusercontent.com/u/916489?v=3","gravatar_id":"","url":"https://api.github.com/users/navstev0","html_url":"https://github.com/navstev0","followers_url":"https://api.github.com/users/navstev0/followers","following_url":"https://api.github.com/users/navstev0/following{/other_user}","gists_url":"https://api.github.com/users/navstev0/gists{/gist_id}","starred_url":"https://api.github.com/users/navstev0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/navstev0/subscriptions","organizations_url":"https://api.github.com/users/navstev0/orgs","repos_url":"https://api.github.com/users/navstev0/repos","events_url":"https://api.github.com/users/navstev0/events{/privacy}","received_events_url":"https://api.github.com/users/navstev0/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-01-26T19:01:43Z","updated_at":"2016-01-28T17:19:40Z","closed_at":null,"body":"The purpose is for testing, however i can not test if creating two different ZWave objects trigger events for each other. The expected output of this program is\r\n```\r\nfirst scanning pass\r\nDisconnecting from one\r\ndisconnect from one connecting to two\r\n```\r\n\r\nHowever the output is \r\n\r\n```\r\nfirst scanning pass\r\nsecond scanning pass\r\nDisconnecting from one\r\n```\r\nAs you can see the zwave.on and zwave2.on are both using the same memory.\r\n\r\n```\r\nvar ZWave = require('openzwave-shared');\r\n\r\nvar zwave = new ZWave({\r\n  ConsoleOutput : false\r\n});\r\nvar zwave2 = new ZWave({\r\n  ConsoleOutput : false\r\n});\r\n\r\nzwave.on('driver ready', function(homeid) {\r\n  console.log('first scanning pass' );\r\n  setTimeout( function() {\r\n    console.log( \"Disconnecting from one\" );\r\n    zwave.disconnect('/dev/cu.usbmodem1411');\r\n    console.log( \"disconnect from one connecting to two\" );\r\n    //zwave2.connect( '/dev/cu.usbmodem1411' );\r\n  }, 1 );\r\n});\r\n\r\nzwave.on('driver failed', function() {\r\n  console.log( \"driver failed for one\" );\r\n  zwave.disconnect();\r\n} );\r\n\r\nzwave2.on( 'driver ready', function(homeid){\r\n  console.log( 'second scanning pass' );\r\n  setTimeout( function() {\r\n    //zwave2.disconnect('/dev/cu.usbmodem1411' );\r\n    process.exit();\r\n  }, 2500 );\r\n});\r\n\r\nzwave2.on('driver failed', function() {\r\n  console.log( \"driver failed for two\" );\r\n  zwave2.disconnect();\r\n} );\r\n\r\nzwave.connect('/dev/cu.usbmodem1411');\r\n```"},"comment":{"url":"https://api.github.com/repos/OpenZWave/node-openzwave-shared/issues/comments/176289939","html_url":"https://github.com/OpenZWave/node-openzwave-shared/issues/59#issuecomment-176289939","issue_url":"https://api.github.com/repos/OpenZWave/node-openzwave-shared/issues/59","id":176289939,"user":{"login":"navstev0","id":916489,"avatar_url":"https://avatars.githubusercontent.com/u/916489?v=3","gravatar_id":"","url":"https://api.github.com/users/navstev0","html_url":"https://github.com/navstev0","followers_url":"https://api.github.com/users/navstev0/followers","following_url":"https://api.github.com/users/navstev0/following{/other_user}","gists_url":"https://api.github.com/users/navstev0/gists{/gist_id}","starred_url":"https://api.github.com/users/navstev0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/navstev0/subscriptions","organizations_url":"https://api.github.com/users/navstev0/orgs","repos_url":"https://api.github.com/users/navstev0/repos","events_url":"https://api.github.com/users/navstev0/events{/privacy}","received_events_url":"https://api.github.com/users/navstev0/received_events","type":"User","site_admin":false},"created_at":"2016-01-28T17:19:40Z","updated_at":"2016-01-28T17:19:40Z","body":"That makes sense. I have tried to use a single zwave object and trigger removeAllListeners prior to writing creating the 2nd set of events, however found that doing zwave.disconnect and then at a later point doing another zwave.connect will cause one of two issues.\r\n```\r\nSegmentation fault: 11\r\n```\r\nor\r\n```\r\n2016-01-28 10:13:44.460 Error, Options have not been created and locked. Exiting...\r\n2016-01-28 10:13:44.460 Error, Exception: Manager.cpp:95 - 0 - Options Not Created and Locked\r\nError: Manager.cpp:95 - Options Not Created and Locked\r\n```\r\n\r\nI have made changes to my test to reflect this. The different errors will show up when changing the timeout values, or removing the times all together.\r\n\r\n```\r\nvar ZWave = require('openzwave-shared');\r\n\r\nvar zwave = new ZWave({\r\n  ConsoleOutput : false\r\n});\r\n\r\nfunction setupEventsZ1(){\r\n  zwave.removeAllListeners();\r\n  zwave.on('driver ready', function(homeid) {\r\n    console.log('first scanning pass' );\r\n    setTimeout( function() {\r\n      console.log( \"Disconnecting from one\" );\r\n      zwave.disconnect('/dev/cu.usbmodem1411');\r\n      setTimeout( function(){\r\n        console.log( \"disconnect from one connecting to two\" );\r\n        setupEventsZ2();\r\n        zwave.connect( '/dev/cu.usbmodem1411' );\r\n      }, 1000 );\r\n    }, 1000 );\r\n  });\r\n\r\n  zwave.on('driver failed', function() {\r\n    console.log( \"driver failed for one\" );\r\n    zwave.disconnect();\r\n  } );\r\n}\r\n\r\nfunction setupEventsZ2(){\r\n  zwave.removeAllListeners();\r\n  zwave.on( 'driver ready', function(homeid){\r\n    console.log( 'second scanning pass' );\r\n    setTimeout( function() {\r\n      zwave2.disconnect('/dev/cu.usbmodem1411' );\r\n      process.exit();\r\n    }, 2500 );\r\n  });\r\n\r\n  zwave.on('driver failed', function() {\r\n    console.log( \"driver failed for two\" );\r\n    zwave.disconnect();\r\n  } );\r\n}\r\n\r\nsetupEventsZ1();\r\nzwave.connect('/dev/cu.usbmodem1411');\r\n```"}}