I have a little program that generates a Simplex noise based isometric voxel-like 2.5D terrain (with varriable width and height).
The program is clearly far from perfect but it's not the main cause of concern.
In my main file, I load a new terrainobject and allow scaling/moving through mousewheel and arrow keys.
When you hit F5. Load gets called but with adjusted scaling/ x/ y so the new terrain object (random seed) is in the same position and scaled like the old one.
So far so good. Now the issue: if I don't set my game.terrain to nil before creating a new terrain, garbage collection never seems to notice that the old one has no more references. My memory usage goes up by 500mb/refresh and the game crashes at 2GB.
Is this expected behavior? Am I always supposed to execute game.terrain = nil before loading in a new object? Or is this faulty GC?
Code: Select all
function love.load()
--- INIT VALUES
game.t = 0
game.fps = 0
game.mX, game.mY = 0, 0
game.mapX, game.mapY = 0, 0
---// INIT VALUES
--- CONSTANTS
game.width, game.height, game.size= 501,501,20
---//
game.dx, game.dy = Terrain.getCenter(game.width, game.height, game.size)
game.x, game.y = game.x or love.graphics.getWidth()/2 - game.dx, game.y or love.graphics.getHeight()/2 - game.dy
--game.terrain = nil <---------------------------
game.terrain = Terrain.new(game.x, game.y ,game.width, game.height, game.size)
game.terrain.scale = game.scale or game.terrain.scale
end