I have a memory leak in my java game application, that I was somehow expecting. The leak comes from a new instance being created multiple times on this button action listener, because each time I press the button it creates a new instance of RegularMode:
btnRegular.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.remove(pane);
gm = Gamemode.REGULAR;
mode = new RegularMode(frame, WIDTH, HEIGHT);
}
});
Funny thing is, I have been trying to fix the memory leak, using this code:
public static void initDisplay() {
gm = Gamemode.NONE;
mode.setRunning(false);
frame.remove(mode.getPane());
frame.add(pane);
frame.validate();
frame.repaint();
mode = null; // THIS LINE
frame.pack();
}
– but it doesn't work. Are there any other ways to solve this type of memory leak?
I have a memory leak in my java game application, that I was somehow expecting. The leak comes from a new instance being created multiple times on this button action listener:
btnRegular.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.remove(pane);
gm = Gamemode.REGULAR;
mode = new RegularMode(frame, WIDTH, HEIGHT);
}
});
Funny thing is, I have been trying to fix the memory leak, using this code:
public static void initDisplay() {
gm = Gamemode.NONE;
mode.setRunning(false);
frame.remove(mode.getPane());
frame.add(pane);
frame.validate();
frame.repaint();
mode = null; // THIS LINE
frame.pack();
}
– but it doesn't work. Are there any other ways to solve this type of memory leak?
I have a memory leak in my java game application, that I was somehow expecting. The leak comes from a new instance being created multiple times on this button action listener, because each time I press the button it creates a new instance of RegularMode:
btnRegular.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.remove(pane);
gm = Gamemode.REGULAR;
mode = new RegularMode(frame, WIDTH, HEIGHT);
}
});
Funny thing is, I have been trying to fix the memory leak, using this code:
public static void initDisplay() {
gm = Gamemode.NONE;
mode.setRunning(false);
frame.remove(mode.getPane());
frame.add(pane);
frame.validate();
frame.repaint();
mode = null; // THIS LINE
frame.pack();
}
– but it doesn't work. Are there any other ways to solve this type of memory leak?
Java: Fix memory leak
I have a memory leak in my java game application, that I was somehow expecting. The leak comes from a new instance being created multiple times on this button action listener:
btnRegular.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.remove(pane);
gm = Gamemode.REGULAR;
mode = new RegularMode(frame, WIDTH, HEIGHT);
}
});
Funny thing is, I have been trying to fix the memory leak, using this code:
public static void initDisplay() {
gm = Gamemode.NONE;
mode.setRunning(false);
frame.remove(mode.getPane());
frame.add(pane);
frame.validate();
frame.repaint();
mode = null; // THIS LINE
frame.pack();
}
– but it doesn't work. Are there any other ways to solve this type of memory leak?