RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Tip: Relation Between Static Keyword and Memory Allocation

Learn more about how to use the static keyword regarding memory allocation.


In Java, static keyword usage on variables means that memory is allocated and it will not be possible for the garbage collector to reclaim the memory until the application terminates. To be clear, do not use static keyword for variables that are local (used within a scope).

Use static only for those variables that needs to be accessed across and also be sure that they are not memory intensive ,so that they do not block huge memory allocation.

Also, variables declared as static can exist even without a class instance. So, be sure on the usage of static given the memory that is allocated and never released until the application exits.

Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date