I commonly encounter the dilemma you describe in the main method of my applications; I want to initialize the application class, but don't need a reference to it after that, for example:
public class MyApplication {
public MyApplication() {
// Initialize and run application
}
public static void main(String[] args) {
new MyApplication();
}
}
Some consider this a code smell. However adding a local variable or field just to keep a useless reference also seems wrong. The short answer to your question: there are no negative side effects and whether the design is bad or not is up for debate.
One way 'around' this is to be more puristic about your constructor. One could reason constructors should be used for initialization only, not for starting up your application. Then you could separate these concerns as follows:
public class MyApplication {
public MyApplication() {
// Initialize application
}
public void run() {
// Run application
}
public static void main(String[] args) {
MyApplication app = new MyApplication();
app.run();
}
}
You can defend this as a valid design decision, and it also solves your unreferenced instance problem at the same time!