Q
qazmlp
The following code has memory leaks(due to incorrect pop()
implementation). But, the 'Heap Analysis Tool' does not report any
such leaks. Can anybody clarify it?
public class Stack {
public static void main (String []a) {
Stack stackInst = new Stack() ;
String str = new String("String");
stackInst.push( str ) ;
stackInst.pop();
}
private static final int MAXLEN = 10;
private Object stk[] = new Object[MAXLEN];
private int stkp = -1;
public void push(Object p) {
stk[++stkp] = p;
}
public Object pop() {
return stk[stkp--];
}
}
Commands used:
java -Xrunhprof:file=java.hprof,format=b Stack
hat/bin/hat java.hprof
implementation). But, the 'Heap Analysis Tool' does not report any
such leaks. Can anybody clarify it?
public class Stack {
public static void main (String []a) {
Stack stackInst = new Stack() ;
String str = new String("String");
stackInst.push( str ) ;
stackInst.pop();
}
private static final int MAXLEN = 10;
private Object stk[] = new Object[MAXLEN];
private int stkp = -1;
public void push(Object p) {
stk[++stkp] = p;
}
public Object pop() {
return stk[stkp--];
}
}
Commands used:
java -Xrunhprof:file=java.hprof,format=b Stack
hat/bin/hat java.hprof