title: How can I delete object in other method in Java?
body: <p><br />
  I wonder how can I remove object in other method, for example I want to delete the <code>dog</code> object in <code>deleteObject</code> method, but it just deletes the current reference to the object!
  Is there any solution or not?</p>
  
  <pre><code>public class Main {
      public static void main(String[] args) {
          Dog dog = new Dog("Max");
          deleteObject(dog);
          System.out.println(dog.toString()); //it still exists! I want to remove it
      }
  
      public static void deleteObject(Dog dog) {
            dog = null; //I want to remove this object but it deletes just this method's reference
      }
  }
  
  class Dog {
      private String name;
  
      public Dog(String name) {
          this.name=name;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>