Listener feature completed #3

Closed
wants to merge 5 commits into
from

Projects

None yet

2 participants

@nathanh89
Contributor

Listener is open for basic dependency injection for tests and the reader is closed at program exit. Updated To-Do and feature lists to reflect changes.

@leadVisionary

This is incorrect. You're creating a new instance and then closing the reader that belongs to that one, not the one you used to populate the String userInput. If you explore some profiling tools, you should be able to diagnose a memory leak and see that you've nicely written a virus. :)

What you need to do is retain an instance of the original listener you create to get the user's input string (as opposed to getting a new one every time) and then call closeListener on that original instance.

Remember that object creation is expensive and needs to be carefully managed.
http://oreilly.com/catalog/javapt/chapter/ch04.html
http://en.wikipedia.org/wiki/Flyweight_pattern

@leadVisionary

You should hang on to the reference of the Listener you create and keep calling getInput() on that one, not create a new one every time.

Listener inputGrabber = Listener.create();
String firstInput = inputGrabber.getInput();
String secondInput = inputGrabber.getInput();

@leadVisionary
Member

This isn't quite there. Clean up the issues in the comments.

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