File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes static variable memory allocation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static variable memory allocation" Watch "static variable memory allocation" New topic

static variable memory allocation

vijaya bharath
Ranch Hand

Joined: Jun 10, 2005
Posts: 66

I have a doubt. Memory for static variable will be allotted at compile time. What if i write a class with 50000 static variables and compile that and never use that class. What about the memory allotted.Is it waste of memory?

Regards,<br />Vijaya Bharath.<br />SCJP1.4 <br />SCWCD5.0
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
The memory will be allotted when the class is *loaded* at runtime. A class that doesn't get used doesn't get loaded, so no, it wouldn't have any effect on memory consumption.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
vijaya bharath
Ranch Hand

Joined: Jun 10, 2005
Posts: 66
Thanks for your reply
I agree. Here's the link:
subject: static variable memory allocation
jQuery in Action, 3rd edition