Once there are no references to an object, the garbage collector will eventually purge those objects from memory.
In practice, that means using objects and functions, so there's an extremely small number of things that actually reference any memory. To use your example, it'd be something like:
In practice, that means using objects and functions, so there's an extremely small number of things that actually reference any memory. To use your example, it'd be something like:
if level_complete: sprites_in_level = [] # any sprites that were loaded in that level are now not referenced, and will be garbage collected # load the sprites needed for the new level current_level += 1 for sprite in LevelSprites(current_level): sprites_in_level.append(sprite.load())