When a class is unloaded from heap memory

Possible duplicate:
Class unloading in java?

When is a class unloaded from memory?

To load a class, we can call Class.forName("NameOfClass");or when we create a class object, then the class is loaded into memory.

+5
source share
3 answers

Classes

Classes will be loaded by the class loader and will (may) be unloaded when this class loader is garbage collected. In normal applications where we do not need loader classes: classes will never be unloaded.

Class / Object Instances

Objects will be created on the heap and deleted when the garbage collector detects that there is no longer a reference to this instance / object.

( , : . Java?)

+2

:

, ( ) , - .

+1

When an exactly unloadable class is not defined, just like how exactly an object can be collected with garbage is not defined. Determined when it can be unloaded:

A class or interface can be unloaded if and only if its loader class-defining can be disposed of by the garbage collector

0
source

All Articles