I was playing as a machine empire and my starbase was under attack, it was almost defeated with no shields no armor and just a little bit of hull, It had two buildings, a shipyard and a hangar. I paused the game and dismantled shipyard, I unpaused a game and hull, armor and shields were restored. When it was down to few percent of hull I sold a hangar and starbase was repaired again.