Skip to content
This repository was archived by the owner on Mar 17, 2020. It is now read-only.

Commit e2cf9a6

Browse files
committed
Big memory leak fixed
1 parent 15e2f5f commit e2cf9a6

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/managers/PlayState.java

+13-14
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,18 @@ class PlayState {
3030
private float bestShipLifeTime;
3131
private String currentBestShipStats;
3232

33+
private SpriteBatch spriteBatch;
34+
private BitmapFont font;
35+
3336
PlayState() {
37+
sr = new ShapeRenderer();
38+
ships = new ArrayList<>();
39+
storedShips = new ArrayList<>();
40+
asteroids = new ArrayList<>();
41+
food = new ArrayList<>();
42+
spriteBatch = new SpriteBatch();
43+
font = new BitmapFont();
44+
3445
init();
3546
}
3647

@@ -44,15 +55,9 @@ else if (elitism < 0)
4455
}
4556

4657
private void init() {
47-
sr = new ShapeRenderer();
48-
49-
ships = new ArrayList<>();
50-
storedShips = new ArrayList<>();
51-
asteroids = new ArrayList<>();
52-
food = new ArrayList<>();
53-
5458
numShips = Settings.NUMBER_OF_SHIPS;
55-
59+
numAsteroids = Settings.NUMBER_OF_ASTEROIDS;
60+
numFood = Settings.NUMBER_OF_FOOD;
5661
setElitism(Settings.ELITISM);
5762

5863
spawnShips();
@@ -61,9 +66,6 @@ private void init() {
6166
printGenerationHeader();
6267
printPopulation();
6368
}
64-
65-
numAsteroids = Settings.NUMBER_OF_ASTEROIDS;
66-
numFood = Settings.NUMBER_OF_FOOD;
6769
}
6870

6971
private void spawnSingleShip() {
@@ -339,9 +341,6 @@ private void drawFood() {
339341
}
340342

341343
private void drawStats() {
342-
SpriteBatch spriteBatch = new SpriteBatch();
343-
BitmapFont font = new BitmapFont();
344-
345344
if (!ships.isEmpty()) {
346345
Ship currentBestShip = ships.get(ships.size() - 1);
347346
currentBestShipStats = currentBestShip.toString();

0 commit comments

Comments
 (0)