Everyone
Everyone

Reputation: 2376

Why can a class not be unloaded without unloading the classloader?

The answer to 'unloading classes in java' says -

"The only way that a Class can be unloaded is if the Classloader used is garbage collected." I took a look at the JLS but couldn't understand it

Why is this the case?

Upvotes: 5

Views: 1087

Answers (1)

Nick Moore
Nick Moore

Reputation: 15857

A class is only unloaded when it is garbage collected, and for that to happen there must be no references to it anywhere. And the classloader keeps a reference to each class it loads.

Upvotes: 13

Related Questions