Is it possible to destroy static variables programmatically?

I want to destroy static object programmatically. Is it possible? If yes then how can i achieve this. Kindly suggest.


The thing that you need to understand is - the references are static, the objects aren't. By that, I mean to say, in

static SomeClass someClassInstance = new SomeClassInstance();

the static property is on the reference someClassInstance and GC acts on instances / objects.

someClassInstance =null will make the first SomeClassInstance eligible for GC.


By definition, a static variable is defined once per class and ( if declared final) has an immutable value ... and cannot be "destroyed".

What are you really trying to do?


in java I don't think you can destroy a variable, if you really meant to free the memory space then the JVM is the one that collects or frees the memory of the unused variables. This process is called as garbage collection. How to do this? Refer:https://stackoverflow.com/a/1567996/1904479

链接地址: http://www.djcxy.com/p/82860.html

上一篇: 最大化Java堆空间

下一篇: 是否有可能以编程方式销毁静态变量?