...
| Code Block | ||
|---|---|---|
| ||
class NoMemoryLeak {
public static void main(String[] args) throws IOException {
ObjectOutputStream out = new ObjectOutputStream(
new BufferedOutputStream(new FileOutputStream("ser.dat")));
for (int i = 0; i < 1024; i++) {
byte[] arr = new byte[100 * 1024];
Arrays.fill(arr, (byte) i);
out.writeObject(arr);
out.reset(); // resetReset the stream
}
out.close();
}
}
|
...