How to guess the memory consumption of a Java object?

U

Ulrich Scholz

I guess that's a hard question: How to guess the memory consumption of
a Java object? Probably, that depends on the Java virtual machine and
on the operating system.

Lets first assume no inheritance and simple data types only. Maybe
there's a number for that.

Thanks,

Ulrich
 
K

kcwong

I guess that's a hard question: How to guess the memory consumption of
a Java object? Probably, that depends on the Java virtual machine and
on the operating system.

Lets first assume no inheritance and simple data types only. Maybe
there's a number for that.

Thanks,

Ulrich

Besides the other links already posted, let me point you to the Java
Specialists Newsletter, issue 142: http://www.javaspecialists.eu/archive/Issue142.html

Check out the other newsletters while you're there... some are pretty
fun to read or experiment with.
 
L

Lew

kcwong said:
Besides the other links already posted, let me point you to the Java
Specialists Newsletter, issue 142: http://www.javaspecialists.eu/archive/Issue142.html

Check out the other newsletters while you're there... some are pretty
fun to read or experiment with.

Roedy's is the better link. The nobilitas.com link leaves out a lot, like
that the size of an object can vary during runtime and even reduce to zero.

Roedy's doesn't mention that either, but it hints at it when it points out,
A JVM is free to store data any way it pleases internally, big or little endian, with any amount of padding or overhead, though primitives must behave as if they had the official sizes.

What neither link mentions is the influence of run-time optimization.
 
A

Andrew Thompson

Ulrich said:
I guess that's a hard question:

There are no hard questions. The answers* are a
different matter.
..How to guess the memory consumption of
a Java object?

I will ask you a question back.

Why? What is the end purpose of the task?

Try and answer that in terms of "I want to offer the
end user X". Where X is something the end user
might actually care about.

So that might include 'protection of crashing
from lack of memory', or 'warning of low memory',
but most users do not care how 'big' any individual
Java object might consume within the memory
space that the Java application is assigned.

From the developer's POV, it is better to not worry
about the memory size of objects unless/until it
becomes a problem, then it would be best to use
a profiler to determine what the problem is.
...
Lets first assume no inheritance and simple data types only. Maybe
there's a number for that.

(shrugs) 37. (* Also note that WAG's and sarcastic
answers are easy.)

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1
 
K

~kurt

Andrew Thompson said:
There are no hard questions. The answers* are a
different matter.

I don't know - I've spent years trying to determine the correct question
for some problems in the past - and then the answer was easy....

- Kurt
 
A

Andrew Thompson

~kurt said:
I don't know - I've spent years trying to determine the correct question
for some problems in the past ..

(Dismissive) Puhh.. Sounds like philosophy to me.

In any case "What is the correct question?" (..is the
'easy' question that fits my hastily constructed, and
poorly thought out, theory of questions.)
...- and then the answer was easy....

'Question the answer', anyone? ;-)
 
U

Ulrich Scholz

Thanks for all replies.

I will ask you a question back.

Why? What is the end purpose of the task?

Try and answer that in terms of "I want to offer the
end user X". Where X is something the end user
might actually care about.


In some very few words:

Within the project MUSIC (www.ist-music.eu) I work on a method to
automatically adapt and distribute applications of many users on many
devices (http://www.eml-d.de/english/homes/scholz/Arbeiten/
divide_and_conquer-ESSPE07.pdf). We consider small devices.

This requires to map from the properties of an application, e.g.,
ressorce usage, onto user happiness (utility). Memory is a ressource.

For the relevant parts of applications we ask the application
developer to help us, i.e., the adaptation mechanism. That means: She
writes the utility function by hand. But for some trivial cases it
would be nice to lift some weight from her shoulders. Here comes in
my question.

OK?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top