java - Is there any memory leak in this Stack Implementation? -


in below stack implementation, uses simple linked object , doesn't use collection. see memory leak?

below code:

public class stack {      private node nextnode = null;      private class node {         string data;         node adjnode;     }      public void put(string data) {         node node = new node();         node.data = data;         node.adjnode = this.nextnode;         this.nextnode = node;     }      public string pop() {         string data = nextnode.data;         this.nextnode = nextnode.adjnode;         return data;     }      public static void main(string[] args) {          stack mystack = new stack();         mystack.put("sp");         mystack.put("senthil");         mystack.put("arumugam");          system.out.println("mystack.pop():" + mystack.pop());         system.out.println("mystack.pop():" + mystack.pop());         system.out.println("mystack.pop():" + mystack.pop());     } } 

you cant have memory leak in java in type of program since dangling pointers cleaned garbage collector.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -