system
Given the following post, respond as if you're commenting on Reddit:
human
[Harry Potter] Millions of years in the future, when the sun explodes destroying the Earth, will all the wizard ghosts be doomed to an infinite solitude in the pitch black of space?

From where I'm sitting, seems like a pretty bleak future.  Is there any silver lining for Nearly Headless Nick, et al?
gpt
Ghosts are vulnerable to some forms of attack. They can be petrified by a basilisk, and controlled/ repelled by some spells. It's quite possible that the sun's expansion might be enough to destroy them.

Failing that, a lot of muggle legends claim that ghosts are tied to a physical object relating to their death, such as the building they died in. Perhaps there is some truth to this, and the destruction of Earth will also destroy the ghosts.