When I go to sleep after having worked on something complex and didn't fully resolve it, I'll almost always dream about trying to solve it. Sometimes I see code, sometimes it's more abstract, but it's always disconcerting. My wife says I mumble things like, "I'm pretty sure 'also' is a keyword unless I'm losing my mind and need to check the documentation"
That's why I like to play some easy games or read a book 1hr before going to sleep. Sometimes they induce creativity though and are counter-active.