ITeye博客

你能看出不合理的地方吗(内存方面)

tmrp · 2009-09-10 21:59 · Markdown

// BAD CODE - DO NOT EMULATE public class LeakyChecksum { private byte byteArray;

public synchronized int getFileChecksum(String fileName) {
    int len = getFileSize(fileName);
    if (byteArray == null || byteArray.length < len)
        byteArray = new byte;
    readFileContents(fileName, byteArray);
    // calculate checksum and return it
}

}

public class LeakyStack { private Object elements = new Object; private int size = 0;

public void push(Object o) { elements = o; }

public Object pop() { 
    if (size == 0)
        throw new EmptyStackException();
    else {
        Object result = elements;
        // elements = null;
        return result;
    } 
}

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。