This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Question of memory consumption for variable" Watch "Question of memory consumption for variable" New topic

Question of memory consumption for variable

avseq anthoy
Ranch Hand

Joined: Apr 27, 2004
Posts: 106
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.

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

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 -
Have you checked out Aspose?
subject: Question of memory consumption for variable
It's not a secret anymore!