GeeCON Prague 2014*
The moose likes Java in General and the fly likes Question of memory consumption for variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Question of memory consumption for variable" Watch "Question of memory consumption for variable" New topic
Author

Question of memory consumption for variable

avseq anthoy
Ranch Hand

Joined: Apr 27, 2004
Posts: 104
Dear all
I have two variable as below


I want to use a object to encapsulae these variables.


If I use a object to to encapsulae these variables , it will be more memory consumption than the original way?





I have to refactor a complicated code recently, and I want to encapsulate some complex structure and variables into a object.
But it will create many object in tthe code.
ex:


So I want to know if I save some information in a object , does it will be more memory consumption than before?
tks


My Way,My Pace
Ravishanker kumar
Ranch Hand

Joined: Jul 20, 2006
Posts: 53
According to my understanding, yes...there will be little more memory consumed by program in second case, because you are creating one additional object of class Person. But that is fine to make program object oriented.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Of course the Person version has more overhead. Think about it, you create an object of type Person and String objects, as opposed to only String objects. But the difference in memory footprint and performance is miniscule and above all the whole concept of OOP is making your architecture object oriented.


JDBCSupport - An easy to use, light-weight JDBC framework -
 
GeeCON Prague 2014
 
subject: Question of memory consumption for variable