I have created an Game class which has a dictionary attribute of players as an attribute, which should have ~36 players in it.
I am iterating though a loop, creating a new instance of a Game object with each iteration and printing the contents of each player onto a csv file.
However, with each iteration although a new object is created, it seems that the player attribute is being appended to rather than being garbage collected.
sheet = open('playerGames.csv', 'w+')
gameNum = 2018020001
while gameNum < 2018020015:
game = Game(gameNum)
print(len(game.players), end=", ")
for player in game.players:
for stat in game.players[player]:
sheet.write(str(game.players[player][stat]) + ",")
sheet.write("\n")
game = None
gameNum = gameNum + 1
The print statement in the above should print a number about 36 each time however it outputs the following 36, 72, 108, 144, 163, 199, 217, 253, 289, 325, 361, 397, 433, 469
Should the garbage collection not clear this up? I have added the game = None
statement in hopes that the entire object gets collected, however that does not seem to work.