File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Performance and the fly likes Memory usage -- which is better? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Memory usage -- which is better?" Watch "Memory usage -- which is better?" New topic

Memory usage -- which is better?

Kev Adams

Joined: Oct 27, 2009
Posts: 23
I came across some code today that looks like this:

Would it not be better, not only for readability, but for memory usage to do it like this:

My thinking is that Java has to create a temporary memory space to hold whatever is returned by getObjA().getObjB().getObjC() each time.

Is that correct?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Performance / memory use is not the issue here, the ability to debug and maintain the code is.

If any of those compound statements threw a NullPointerException, where would you look?

"Premature optimization is the root of all evil"

I agree. Here's the link:
subject: Memory usage -- which is better?
jQuery in Action, 3rd edition