• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Adds the specified class to a Vector to keep it from being

 
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can someone explain in more detail how this works or point me to resources

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess this is done because of the following: If there are no instances anymore of a class, the JVM could unload the class. Static members in the class would then also be garbage collected. If the application saves state in such variables, that state would be lost. If the application would later create a new instance of the class, the class would be loaded again and the static members would be initialised to their starting values instead of the saved state.

By keeping a reference to the class in a vector, you force the JVM to not unload it (it can't unload the class if the application still has a reference to it).

I found also this page about unloading classes: Class unloading - Clarifications and Amendments to the JLS - This was a change made in Java 1.2.

More info: Find out how Java 1.2 changes the way we load and unload classes in Java

Probably you don't need this trick with keeping a reference in a vector if you're using Java 1.2 or newer.
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jesper, thanks I understand it better now
 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic