static variables, what is their life span?

I am using static variables in my app, lots of them. My question is, when I exit the app will they be still in memory..? If yes, how can I correct this. Thanks in advance.


Static variable gets loaded when class is loaded by ClassLoader, and would be removed when it is Unloaded

For the Next Readers of this question-

As Everybody said in the answer that static variables are class variables. They remain in the memory until the class is not unload from JVM.

In Android you have seen that when we close any application then it does not close completely, It remains in the recent application stack, That you can see by long press the home button(On Most Devices).

 Android itself kicked out those recent apps when the other app needs memory

In Android, static variable unload when-

 -You force stop your app.
 -Application crashes.
 -You clear your app data.
 -Switch off your Device.
 -Android kicked out recent app  

In addition to the other answers, also note that if those static "variables" are actually "static final" primitive constants, then they don't really exist as separate entities at all, but their value gets compiled right into all the classes that use them (not just the one that defines them).

The static variable will live as long as the class is loaded in the JVM. When there are no more instances of the class being ran in the JVM the class will be unloaded and the static variable will be eligable for garbage collection.

Static variables are associated with a class and they will live as long as the class is in the memory(which ceases to exist once your application terminates).

Sometimes, you want to have variables that are common to all objects. This is accomplished with the static modifier. Fields that have the static modifier in their declaration are called static fields or class variables. They are associated with the class, rather than with any object.Every instance of the class shares a class variable, which is in one fixed location in memory. Any object can change the value of a class variable, but class variables can also be manipulated without creating an instance of the class.

When instance is not use, garbage collector will be destroy it. it means that your instance will erased from memory.

I am using static variables in my app, lots of them.

Static variables are immune against automatic memory manager and you should to set them to null in onDestroy method(Android). They belong a class sure and exactly it works as meant @Jigar Joshi.

if it is C/C++, and if you didnt collect the garbages, you should use a memory management program. İf it is java, close any "javaw" programs from memory and close jvm

static variable's are called class variable and in way of scope they loaded when the class is loaded and unloaded when class is unloaded. for example a class variable like

private int classinVar;

is automatically initialized by its default value when class loaded, and same concept is with signout when you get signout then that class would go out of context with its static field.

Need Your Help

SQL Server JDBC Error on Java 8: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption

java sql-server linux ssl jdbc

I am getting the following error when connecting to a SQL Server database using version the Microsoft JDBC Driver:

How to concatenate values in RDLC expression? dataset reporting field rdlc

I have an RDLC file in which I want to make an expression.