Linked by Thom Holwerda on Fri 14th Sep 2012 02:30 UTC, submitted by MOS6510
Java "As a typical Java developer I never monitored the memory usage of my application apart from following typical best practices like closing the connections, streams etc. Recently we were struck with few issues in our JBoss servers that I had to dig in to the memory management."
Thread beginning with comment 535254
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[6]: Memory management
by raboof on Sat 15th Sep 2012 19:18 UTC in reply to "RE[5]: Memory management"
raboof
Member since:
2005-07-24

static analysis can tell the JVM or compiler whether the variable is used any more, and if it's not, it can be GC'ed, whether it's set to NULL or not.

This is true, but only for local variables.

For fields, there may be cases where an object needs to be kept alive, but one of its fields can be discarded, so setting it to NULL is advantageous. Static analysis won't help there, taking into account Java has a reflection API. Indeed, though, such cases are probably rare, and a form of code smell in the first place.

Reply Parent Score: 2

RE[7]: Memory management
by siride on Sat 15th Sep 2012 22:09 in reply to "RE[6]: Memory management"
siride Member since:
2006-01-02

Yes, you are correct. I was only thinking about local variables.

There is little need, however, to have fields that would become unused while the owning object remained in use. In such a case, they shouldn't be fields. That's not to say that people won't do the wrong thing. I assume that's what you were talking about with your code smell comment.

Reply Parent Score: 2

RE[8]: Memory management
by raboof on Sat 15th Sep 2012 22:19 in reply to "RE[7]: Memory management"
raboof Member since:
2005-07-24

There is little need, however, to have fields that would become unused while the owning object remained in use. In such a case, they shouldn't be fields. That's not to say that people won't do the wrong thing. I assume that's what you were talking about with your code smell comment.

Yes, exactly.

Reply Parent Score: 2