Right now I’m reading this article regarding Java Garbage Collection: http://www.javaworld.com/javaworld/jw-08-1996/jw-08-gc.html?
Here is a snippet of a function in a JMS client
public void foo(){
...//Create Connection factory, connection, and session, topic
TopicSubscriber tp = session.createDurableSubcriber(topic,"001");
tp.setMessageListener(this)
}
This question isn’t about JMS but more what happens with the object “tp” after foo() function call has ended. After the function ends there is no way to reference tp anymore. I’m assuming in createDurableSubscriber() that it’s using the keyword “new” which means that the object is being placed on the JVM heap. However since tp can no longer be referenced is it subject to the JVM garbage collection?
You need to look in the source code for
session.createDurableSubcriber()to see if it doesn’t store the value it will return to you somewhere.Remember you are basically getting a pointer (called reference in Java) to the object, not the object itself, and that pointer can be stored numerous places even if you only have a single object. All these pointer references must be done with before the object can be reclaimed by the garbage collector.