destroy a class

Discussion in 'Spigot Plugin Development' started by TheFuzzyHead5, May 28, 2017.

  1. How can I go about destroying an instance of a class.

    For example, there are many runnables going inside the class instance. How could I just essentially kill the class
     
  2. Mas

    Mas

    Set the instance of the class to null; you'll want to cancel all the runnables first to prevent anything bad from happening.
     
  3. You cant, java does not support that sort of cleanup: it has garbage collection to automatically (in theory) remove forgotten objects instead.

    Just clear (either with null, or a reference to a diferent object, or by the object containing the reference being GCed itself) every reference to the object, and it will be deleted. If it is a runnable, you also need to cancel it, as the class that schedules runnables naturally has a reference to it.
     
    • Like Like x 1