Submitted by: M S Sridhar(sridhar.ms@gmail.com)

Friday Nov 16th 2018 by M S Sridhar

Language: Java, Expertise: Intermediate - 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.

Mobile Site | Full Site