...
| Code Block | ||
|---|---|---|
| ||
class MyFrame extends JFrame {
private byte[] buffer = new byte[16 * 1024 * 1024];
// Persists for at least two GC cycles
}
|
Compliant Solution (Superclass's finalizer)
When a superclass defines a finalize() method, make sure to decouple the objects that can be immediately garbage collected from those that must depend on the finalizer. This compliant solution ensures that the buffer can be reclaimed as soon as the object becomes unreachable.
...