SBoudrias/Inquirer.js — pull request #63 by danielchatfield (2013-09-02 15:49:10+00:00)
Title: Call streams end to trigger cleanup (fix #62)

From #62

>[`cleanup`](https://github.com/joyent/node/blob/v0.11.6-release/lib/stream.js#L102) isn't being called. It is called automatically when:

>- the `end` event is emitted on the `source`
- the `close` event is emitted on the `source`
- the `close` event is emitted on the `destination`

>Since the `destination` is `process.stdout` we can't close that. We close the `readline` interface but this does not close the input or the output streams so `cleanup` is never fired.

>To fix this leak we need to call mute-stream's `end` method.

>By adding `this.rl.output.end();` the above test doesn't fail (but it currently causes other tests to fail). I'm investigating the other tests now (at least one of them I can see is because we overwrite the output stream with something that doesn't have an `end` method).

Patch includes a change to the test to prevent a regression, ideally I'd want to add a separate test that catches any sort of memory leak but currently the node warning is just a `console.error` call so I can't see a way of "catching" it to fail the test.

// cc: @SBoudrias