I actually considered that as a realistic possibility -- that memories of dreams form as you wake up -- but I think that is didproved by people talking and moving in their sleep in ways consistent with what they report about their dreams when they wake up. PET and NMR scanning might be able to resolve the issue, if it has not done so already.