In an example of the @remove annotation on a stateful EJB, the annotated method nullifys the bean's instance variables. Why? Surely destroying the bean destroys its contents, i.e. any variables?
Thanks, Jon
In an example of the @remove annotation on a stateful EJB, the annotated method nullifys the bean's instance variables. Why? Surely destroying the bean destroys its contents, i.e. any variables?
Thanks, Jon
Setting all fields of an object to null
has two useful effects:
It provides a hard barrier against logic errors that would lead to an invalid object being reused. The application would crash instead of silently producing incorrect results.
It helps the Java VM garbage collector by removing edges from the object reference graph, thus improving the overall performance.
Can you post the example source code? Or don't. Pro-actively setting
null
is not needed - when EJB is destroyed and garbage collected soon later, all objects it references (of course providing there are no other references to them) will be garbage collected as well.