-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryLeakExample.java
More file actions
35 lines (28 loc) · 1.02 KB
/
Copy pathMemoryLeakExample.java
File metadata and controls
35 lines (28 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package org.java;
import javax.swing.*;
import java.awt.event.ActionListener;
public class MemoryLeakExample {
public static void main(String[] args) {
JButton button = new JButton("Clique Aqui");
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(button);
frame.setSize(300, 200);
frame.setVisible(true);
for (int i = 0; i <= 999; i++) {
button.addActionListener(e -> System.out.print("Botão clicado! -"));
}
}
static final ActionListener actionListener = e -> System.out.print("Botão clicado! -");
public static void exampleOk() {
JButton button = new JButton("Clique Aqui");
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(button);
frame.setSize(300, 200);
frame.setVisible(true);
button.addActionListener(actionListener);
// ...
button.removeActionListener(actionListener);
}
}