Psychologists at the University of Notre Dame have discovered that passing through a doorway triggers what's known as an event boundary in the mind, separating one set of thoughts and memories from the next.
Your brain files away the thoughts you had in the previous room and prepares a blank slate for the new locale.
It is referred to as a location-updating effect, and it results in a decline in memory when people move from one location to another.
This may help explain the confusion a person with dementia experiences when they transition from one place to another, as well as when they wander or travel.
Walking through doorways causes forgetting:
Gabriel A. Radvansky, Sabine A. Krawietz, and Andrea K. Tamplin
Department of Psychology, University of Notre Dame, Notre Dame, IN, USA