I'm working on a dueling system for a game that I've been working on, here's the skeleton of the class:
public class Duel {
private Champion challenger;
private Champion defendant;
private boolean duelStarted;
private long timer;
public Duel(Champion challenger, Champion defendant) {..
public void tick() {..
public void declineDuel() {..
public void endDuel(ResultType resultType, Champion winner, Champion forfeit) {..
public void declareWinner(Champion player) {..
public void declareForfeit(Champion player) {..
private enum ResultType {..
public Champion getChallenger() {..
public Champion getDefendant() {..
}
This class will be assigned to the Champion's class for both the challenger, and the defendant.
When a duel ends (Effectively by calling Duel#declineDuel()
or Duel#endDuel(ResultType, Champion, Champion)
or due to something like a Champion#Disconnect()
, how should I properly set the class up to be collected by the Java garbage collection.
I've never completely understood this, would I need to set everything inside of the class to null, as-well as the Duel currentDuel;
declaration in Champion.class
or should I only set the currentDuel to equal null, which will effectively stop referencing ( I would assume, this is what I'm confused about ) to this instance of the class.
I'm don't quite understand what the garbage collection would consider a "Referenced" class, would Duel#getChallenger()
being set make it be considered referenced still, even though it's not being touched from an outside class?
I guess I'm confused between in-bound and out-bound references, would anybody care to shed some enlightenment since I can't seem to understand what's going on when i rtfm.