Lux-AI-Challenge / Lux-Design-S1

Home to the design and engine of the @Lux-AI-Challenge Season 1, hosted on @kaggle
https://lux-ai.org/
Apache License 2.0
897 stars 152 forks source link

Memory leak in cpp kit #89

Closed KursAnd closed 2 years ago

KursAnd commented 2 years ago

I think there are big memory leaks in cpp kit here void resetPlayerStates () { ... players[0].cities.clear (); ... }

cities is std::map<std::string, City *> each turn we make new allocation this->players[team].cities[cityid] = new lux::City (team, cityid, fuel, lightUpkeep); but we never do smth like delete players[team].cities[cityid]; (clear () doesn't do it for dynamic memory)

the same problem with std::vector<CityTile *> citytiles;

because of this, sometimes an error occurs in long games RuntimeError: abort(RuntimeError: abort(Cannot enlarge memory arrays to size 16781312 bytes (OOM). Either (1) compile with -s INITIAL_MEMORY=X with X higher than the current value 16777216, (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ) at Error

I removed these pointers locally and this solved the problem. ...

Check it, please

StoneT2000 commented 2 years ago

fixed by 6da5e78. Left as pointers to avoid changing too much