This is the number one way I really grasp some new technique or area in programming.
During awake time, when I'm actively studying/using a new technique, things can get mixed up. I might be absorbing information, but not necesarily using it very efficiently. I just plow on, trying things out, playing around. (Perhaps because most of what I do is self-directed studying, so getting unstuck is left up to myself.)
After days like this, when I sleep, it's fitful. I'll dream of people tormenting me until I can do something in O(n) time, garbage collectors chasing me, whatever. But oddly, often times when I wake up, I have a calm and a better unstanding of whatever it was I was studying. And sometimes, I'll wake up with a start, with a clear solution to a particular problem in mind.