Statuc methods and static members ...?

A

Amit Kumar

Hi all,

I am facing memory problem in my project . i am usin Static variables.
i want to know till when they remain in memory ?
 
T

Thomas Hawtin

Amit said:
I am facing memory problem in my project . i am usin Static variables.
i want to know till when they remain in memory ?

The objects referred to by the variables will remain in memory until
they are garbage collected at the same time as the Class the variable
belongs to, and the class' ClassLoader. For various reasons that might
not happen, or perhaps may have to wait for a SoftReference to be cleared.

In general it is best not to use *non-final* static variables at all.
Also final statics to mutable structures are also bad. Although they
appear to offer cheap fixes, they make keeping code reliable unfeasibly
difficult.

Tom Hawtin
 
R

Roedy Green

I am facing memory problem in my project . i am usin Static variables.
i want to know till when they remain in memory ?

Unless you are using custom class loaders, they will remain allocated
until your app terminates.
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top