The physical act of passing through a doorway is the reason why you often walk into a room and completely forget what you were doing. Because going through a door signifies the beginning or end of something, this creates an ‘event boundary’ within your mind. Basically, every time you walk through a doorway, your brain starts filing away  thoughts from your previous location  to make room for a new group of  memories in the next.  

(Source, Source 2, Source 3)