In which way does the SceneManager.LoadScene is cloasing old scene?

I have not found information about this in manual, but this kind of knowledge is necessary for me, so I will ask here. In which way does the SceneManager.LoadScene is cloasing old scene?
I faced a problem while making re-start ability after character death.

SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

But after reloading scene there was a huge number of null-reference exceptions on the static variables.
I had thinked that scene reloading fully clears previous scene, but it seems that this process leaves some rubbish wich cause exceptions, because lauching scene with “Play” button in editor is ok.
So I would like to know how clearing scene is realized and is there any ways to fully clear scene?

Try selecting your GameObjects, which have the scripts with your static Variables attached, as DontDestroyOnLoad. You can call DontDestroyOnLoad(gameObject); in that script, inside the Awake() or Start() Method. Then the GameObject won’t “re-load” and maybe prevents your error.


However, if you static Variable is e.g. GameObject, of cause the GameObject gets deleted and the reference therefore is null, which means you have to create a new reference to the new GameObject - if that makes sense.