memory and class loading

S

sriram_kosuri

hi,

1. I got (say 100) java class files.
2. In each there are 1000 "final static String" are defined.
3. Only one\few variable from each of these classes is referred in the
main class.
4. Classloader loads all these class files into memory, because there
is reference in main.

Just because I refer to one variable the whole class file is being
loaded.

Comments about memory usage?


rgds
-Sri
 
R

Roedy Green

Just because I refer to one variable the whole class file is being
loaded.

the static variables will be, but the methods are not necessarily
hooked up or jitted until they are used.

I think though they will be interned, so that if you have the same
string in many classes, there will be only one copy of the string.
 
T

Thomas Hawtin

1. I got (say 100) java class files.
2. In each there are 1000 "final static String" are defined.
3. Only one\few variable from each of these classes is referred in the
main class.
4. Classloader loads all these class files into memory, because there
is reference in main.

Just because I refer to one variable the whole class file is being
loaded.

Comments about memory usage?

If you make the static final Strings initialisers compile time
expressions (for instance just a literal String), then the value should
be placed into the referring class at compile time.

But I'd be tempted to change the design.

Tom Hawtin
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top