0

Program structure is like this

public class SampleClass {
    private final MyLogger logger = new MyLogger();
    // other logic
}

MyLogger has a reference to a session scoped singleton Console object:

public class MyLogger{
    private Console console;
    // other logic
}

There are multiple classes having such a final MyLogger reference. The Console object referenced by the logger objects is a session scoped singleton which means all of these classes print on the same console object within a session. When a session is ended, do I need to set console to null for those logger instances? That is, if I don't do anything to handle those loggers, will the console object be garbage collected without too much delay?

CMZS
  • 601
  • 6
  • 21
  • Possible duplicate of [In java when does an object become unreachable?](http://stackoverflow.com/questions/5667705/in-java-when-does-an-object-become-unreachable) – shmosel Oct 14 '16 at 01:31
  • In general you don't have to do anything to make garbage collection work in Java. The only precaution is being sure that an object is not referenced uselessly another objects which you still need, otherwise GC won't work. – Jack Oct 14 '16 at 01:32
  • What was the mechanism you've used to make that a session-scoped singleton? Was that spring framework? – Ivan Oct 14 '16 at 19:39

0 Answers0