Re: Java Memory question
Eric wrote:
That was the first concern mentioned here, to limit scope. If I have
An instance variable has larger scope than a local variable, not more
limited.
2 methods which need an object of the same type but don't share the
value, it uses fewer lines of code to declare one variable in the
"Fewer lines of code" is of no benefit when they introduce a bug.
class to be used by the instance then reuse that variable for each
method to create it's [sic] object which should also reserve a space in
memory for that object and seems like it should run faster, but
If I understood that sentence correctly, and by no means am I sure I
untangled it correctly, then actually you would expect that to run
slower.
You are aware that variables don't own objects and that the connection
between them is temporary, right? Re-using a variable does not
correlate to reserving "a space in memory"; re-using an object does
correlate to memory usage but likely wastes memory rather than saves
it.
Your philosophy to remove scope limits from your objects might account
for your memory issues. Keeping objects around past their useful life
puts memory pressure on your application. Given your tendency to
declare instance-lifetime objects where local ones are more
appropriate, you could be wasting memory quite badly.
apparently duplicating the statement to declare the type of variable
within each method which needs it is better practice and better memory
management.
And faster code.
And it's not a "duplicate" statement. The action is necessary and
productive, not redundant.
Another suggestion I've gotten is upgrading Java. To ensure
stability, we avoid upgrading software on the server and prevent
upgrades on the client where possibile until a newer version is tested
and there's a need for change. Installing newer software is bad if
there's any possibility of introducing new bugs or unexpected change
in functionaility. We're currently running Java 6 Update 17. I hear
there may be significant memory management improvement in Update 18.
Of course the latest is Update 24. It seems this is a good time to
update so I'll have to test the latest
The difference between minor upgrades is not memory management, it's
security and bug fixes. If you are on a Java 6 version prior to u24,
then you are deliberately hanging on to major security flaws and bugs.
Is that really prudent?
--
Lew