Operation FPS bomb has shown that memory and FPS issues seemingly get 99% fixed when you save and reload.
It's like everything you do ingame causes increasing memory usage and lag which gets cleared when refreshed.
We haven't found the cause of fort ending lag yet though.
No, actually, that's not what it shows.
You can create and destroy millions of items, and the game actually reacts to it fairly well without needing to save and reload. I ran a fortress for 10 game years straight without reloading, which took two real-life days of running constantly in the background (granted, alot of that spent paused while I was doing silly things like sleeping), and it was back at essentially its initial memory usage when I had essentially the same number of items in the game.
DF is actually surprisingly very robustly
not memory-leaky considering its degree of complexity.
Creating 10,000 items in a reaction in one of my test forts consumes 5 megs of RAM. (500 bytes per item.) This is done mostly by the fact that every type of item is in multiple types of vectors.
Keep in mind that there may be other factors involved - there is the pathfinding connectivity map, the jobs list (considering that this may create more hauling jobs),
All tiles, revealed, unrevealed, etc. already take up several bites of space. This is already compressed using bitmasks, so that, for example, water and magma depths are treated as 3 bits that determine depth (from 0 to 7) and a single bit that is a flag that determines whether that is magma or water. Magma and water turn to obsidian to prevent a conflict, and no other fluids are supported. There are bitmasks used to determine basically everything else about the status of a tile, as well, but generally, you find things like flags used to declare the identity of a workshop or furniture, while a mere flag bit and a pointer are used for tile map purposes.
To compress data, it's basically one giant array of arrays of arrays that is required to be completely static for the game to work properly, so no data is added to this, and it can run at top efficiency.
Revealed and excavated tiles do take up more memory, however, and slow the game down significantly, simply for being revealed. Simply recording the dirt on the floor takes up some memory, and there's all sorts of pointers that have to point to something that get created for that.
To that guy who said something about flyweight - this already occurs, each "item" in the game is nothing more than a pair (or more) of pointers - a pointer to an item "shape" type, and a pointer to a material type. Certain types of items have more pointers. Art objects, for example, have descriptions and quality types and other properties that need more pointers and consume more memory.
With that said, Toady is using C++ STL vectors, and I do think there could be some general responsiveness gains if he made custom vectors that were specifically designed for randomly removing objects from a list thousands if not millions of members long.