I read a pgn file, extract some information and then write my results back to a file. Why does the python process Way more RAM than my variables combined? Example: After loading 10000 chess games, python needs 700mb of RAM, but the list is only 85kb big. 200,000 games break my machine.
import chess.pgn
from tqdm import tqdm
def load_games(n_games: int) -> list[chess.pgn.Game]:
"""Load n games from the pgn file and return them as a list"""
with open("files\lichess_elite_2022-04.pgn") as pgn_file:
# Downloaded from: https://database.nikonoel.fr/
games = []
for i in tqdm(range(n_games), desc="Loading games", unit=" games"):
game = chess.pgn.read_game(pgn_file)
if game is not None:
games.append(game)
else:
break
return games
games = load_games(10000)
print(games.__sizeof__()/1000)