Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

edited tags
Link
Kara
  • 6.2k
  • 16
  • 54
  • 58
added 81 characters in body
Source Link

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?

Source Link

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?

lang-java

AltStyle によって変換されたページ (->オリジナル) /