Why does Cities Skylines take so long to exit?

  • We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

Norppis

Second Lieutenant
43 Badges
May 22, 2017
120
74
  • Europa Universalis IV: Rule Britannia
  • Stellaris: Digital Anniversary Edition
  • Crusader Kings II
  • Cities: Skylines - Natural Disasters
  • Cities: Skylines - Mass Transit
  • Europa Universalis IV: Mandate of Heaven
  • Stellaris: Synthetic Dawn
  • Cities: Skylines - Green Cities
  • Stellaris: Humanoids Species Pack
  • Stellaris: Apocalypse
  • Stellaris: Leviathans Story Pack
  • Cities: Skylines - Parklife
  • Stellaris: Distant Stars
  • Europa Universalis IV: Dharma
  • Stellaris: Megacorp
  • Europa Universalis IV: Golden Century
  • Stellaris: Ancient Relics
  • Stellaris: Lithoids
  • Stellaris: Federations
  • Europa Universalis 4: Emperor
  • Hearts of Iron IV: Cadet
  • Europa Universalis IV
  • Europa Universalis IV: Call to arms event
  • Cities: Skylines
  • Europa Universalis IV: El Dorado
  • Europa Universalis IV: Common Sense
  • Europa Universalis IV: Mare Nostrum
  • Stellaris: Galaxy Edition
  • Europa Universalis IV: Rights of Man
  • Europa Universalis IV: Third Rome
  • Age of Wonders III
  • Cities: Skylines - Snowfall
  • Europa Universalis IV: Cradle of Civilization
  • Europa Universalis IV: Cossacks
  • Cities: Skylines - After Dark
  • Stellaris
  • Europa Universalis IV: Pre-order
  • Stellaris - Path to Destruction bundle
  • Europa Universalis IV: Res Publica
  • Stellaris: Galaxy Edition
  • Europa Universalis IV: Wealth of Nations
  • Europa Universalis IV: Conquest of Paradise
  • Europa Universalis IV: Art of War
Took me 12 minutes to load my city (from the main menu).
Took 5 minutes to shut down (to desktop), but the laptop was not overly responsive for about another 3 minutes.
Indeed, huge loading and shut-down times (and frequent need to start more than once) are the main reasons I just cannot enjoy C:S like I'd like to. It would be so nice to spend some time every now and then building or optimizing your city.. but C:S makes clear that you have to invest time in opening it only.
 

Fox_NS_CAN

Field Marshal
1 Badges
Oct 26, 2016
2.834
656
  • Major Wiki Contributor
C:S makes clear that you have to invest time in opening it only.
Yeah, I end up loading up UT99. Can be playing in under a minute.
 

SeekTruthFromFx

General
59 Badges
Sep 17, 2013
1.892
2.415
  • Crusader Kings II: Legacy of Rome
  • Hearts of Iron IV: By Blood Alone
  • Crusader Kings II: Sons of Abraham
  • Victoria 2: A House Divided
  • Crusader Kings II
  • Europa Universalis IV: Wealth of Nations
  • Hearts of Iron III
  • Hearts of Iron III: Their Finest Hour
  • Europa Universalis IV: Rule Britannia
  • Hearts of Iron IV: Colonel
  • Hearts of Iron IV: Expansion Pass
  • Europa Universalis IV: Cradle of Civilization
  • Hearts of Iron IV: Death or Dishonor
  • Europa Universalis IV: Mandate of Heaven
  • Crusader Kings II: Monks and Mystics
  • Hearts of Iron IV: Together for Victory
  • Europa Universalis IV: Rights of Man
  • Crusader Kings II: Reapers Due
  • Crusader Kings II: Conclave
  • Hearts of Iron IV: Expansion Pass
  • Europa Universalis IV: Dharma
  • Crusader Kings II: Holy Fury
  • Europa Universalis IV: Golden Century
  • Imperator: Rome
  • Hearts of Iron IV: Expansion Pass
  • Hearts of Iron IV: La Resistance
  • Crusader Kings III
  • Crusader Kings III: Royal Edition
  • Europa Universalis 4: Emperor
  • Victoria 3 Sign Up
  • Victoria 2
  • Cities: Skylines
  • Europa Universalis IV: El Dorado
  • Europa Universalis IV
  • Crusader Kings II: Way of Life
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Cities: Skylines - After Dark
  • Europa Universalis IV: Cossacks
  • Cities: Skylines - Snowfall
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Sword of Islam
  • Europa Universalis IV: Art of War
  • Crusader Kings II: Charlemagne
  • Europa Universalis IV: Res Publica
  • Rome Gold
  • Victoria 2: Heart of Darkness
  • Crusader Kings II: Jade Dragon
  • Europa Universalis IV: Third Rome
  • Europa Universalis IV: Mare Nostrum
I have a couple of suggestions for what might be causing this based on my very, very limited experience with Unity. But I am by no means an expert, so they might be laughably wrong. If anyone points out where I've gone wrong, then I will at least have learned something.

My first observation is that Unity divides games into Scenes (other engines might call these Worlds or Levels). In a platformer, each level might be a separate Scene. In a sports sim, the 3D stadium where you see matches might be one Scene and the 2D screen where you buy and sell players might be a different Scene. In an RPG, when you step out of the Town Square into the Palace, you are probably moving from one Scene into another. Each Scene has a collection of things ("Objects"): they could be football players, swords and shields, whatever. In today's 3D games, each Scene will generally be associated with a 3D space where Unity's graphical side will keep track of the location of each object and report any collisions between them. In the examples above, you will often leave one Scene to go into another, and so it's important that they close down 'nicely'. When the RPG character leaves the Town Square, the graphics memory needs to be thoroughly cleaned of all the old objects so that you don't find muddy puddles inside the Palace. But there's continuity to take care of as well. If you had a loaf of bread in your rucksack in the Town Square, that needs to be noted so that you still have a loaf of bread in your rucksack in the Palace, even though it is in fact a completely new environment and the loaf of bread has been freshly recreated in the new 3D space from the game's files.

This is relevant because each C:S city is one, gargantuan Scene. There can't be many other Unity games with such large and complex Scenes. There are huge numbers of buildings, Cims, etc. But Unity isn't just going to say "blow this for a game of soldiers" and tell the OS to wipe the lot. As far as Unity knows, you might be closing this Scene and moving to another one, and so every Object has to be checked and destroyed carefully. So when you exit C:S, closing it all down nicely is a huge task (or more accurately, millions of small tasks). A lot of data is going to be going through your CPU.

My second observation is that Unity uses the C# programming language, which is a 'garbage collected' language. This means (the next bit is simplified hugely) that the C:S programmers don't directly control the computer's memory. If you demolish a house in C:S, the memory used by that house isn't immediately freed. The house's ID number is just marked with an asterisk in the game's list of house Objects. Every so often (very roughly 30 to 60 seconds), the garbage collector will check all the lists, and if there's an asterisk it will delete the house Object from the list and either re-use the memory or hand it back to the OS. So our lovely friends in Finland don't need to worry about the details of that and can focus on more important things.

But there is a trade-off. In a traditional game, the memory would have been freed up when the house was demolished. Now we have two phases, demolishing the house in-game and then later tidying up the house Object memory. But when you close the Scene, you are suddenly putting an asterisk on every item of every list and when the garbage collector activates it's going to have hundreds of thousands of Objects to tidy up, and at the very same moment that Unity is already force-feeding your CPU with the Scene-closing routines. Because C:S is soooooo memory-hungry and has so many Objects, just processing the lists of Objects must be a major task in itself. And again, the garbage collector has no knowledge that you're closing the game; it doesn't know the difference between a death wave that removes lots of Cim objects and closing to desktop. It doesn't even know that you're playing a game; as far as the garbage collector knows it could be handling bank transactions or phone calls to the emergency services. All it sees are a lot of asterisks on lists and it must process every one carefully and correctly. And that just takes time.
 
Last edited:
  • 3
Reactions:

Fox_NS_CAN

Field Marshal
1 Badges
Oct 26, 2016
2.834
656
  • Major Wiki Contributor
As a person who knows nothing about Unity, or programming in general for that matter, I think your theory sounds plausible.
 
  • 1Like
Reactions:

havenost

Captain
50 Badges
Dec 9, 2013
413
90
  • Crusader Kings II
  • Pillars of Eternity
  • Crusader Kings II: Sword of Islam
  • Mount & Blade: Warband
  • Cities: Skylines - Campus
  • Crusader Kings II: Way of Life
  • Europa Universalis IV: Common Sense
  • Crusader Kings II: Horse Lords
  • Crusader Kings II: Conclave
  • Hearts of Iron IV: Cadet
  • Crusader Kings II: Reapers Due
  • Europa Universalis IV: Rights of Man
  • Crusader Kings II: Monks and Mystics
  • Cities: Skylines - Mass Transit
  • Surviving Mars
  • Age of Wonders III
  • Cities: Skylines - Green Cities
  • Crusader Kings II: Jade Dragon
  • Surviving Mars: Digital Deluxe Edition
  • Cities: Skylines - Parklife
  • Shadowrun Returns
  • Cities: Skylines Industries
  • Crusader Kings II: Holy Fury
  • Europa Universalis III: Collection
  • Cities: Skylines
  • War of the Roses
  • Crusader Kings II: Sons of Abraham
  • Europa Universalis IV
  • Crusader Kings II: The Republic
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II: Charlemagne
  • Cities in Motion 2
  • Europa Universalis IV: El Dorado
  • Europa Universalis III
  • Divine Wind
  • Europa Universalis IV: Art of War
  • For the Motherland
  • Hearts of Iron III
  • Hearts of Iron III: Their Finest Hour
  • Hearts of Iron III Collection
  • Stellaris
  • Cities: Skylines - Snowfall
  • Heir to the Throne
  • Europa Universalis IV: Cossacks
  • Cities: Skylines - After Dark
  • Majesty 2 Collection
  • Semper Fi
  • Magicka 2
SeekTruthFromFx your second observation is probably correct.

Even after exiting the game, as in returning to desktop I can see on my second monitor with task manager that the game takes like 3-5 seconds before it begins releasing the memory. And it does it at a rate of around 300 MB per second. It takes an average of around 30 seconds - 1 minute for the game process to fully shutdown on my system.
 
  • 1Like
Reactions: