Two experiments involving a total of 191 volunteers have investigated the parameters of sleep’s effect on learning. In the first experiment, people learned 40 pairs of words, while in the second experiment, subjects played a card game matching pictures of animals and objects, and also practiced sequences of finger taps. In both groups, half the volunteers were told immediately following the tasks that they would be tested in 10 hours. Some of the participants slept during this time.
As expected, those that slept performed better on the tests (all of them: word recall, visuospatial, and procedural motor memory), but the really interesting bit is that it turned out it was only the people who slept who also knew a test was coming that had improved memory recall. These people showed greater brain activity during deep or "slow wave" sleep, and for these people only, the greater the activity during slow-wave sleep, the better their recall.
Those who didn’t sleep, however, were unaffected by whether they knew there would be a test or not.
Of course, this doesn’t mean you never remember things you don’t intend or want to remember! There is more than one process going on in the encoding and storing of our memories. However, it does confirm the importance of intention, and cast light perhaps on some of your learning failures.
Reference:
[2148]
(2011). Sleep Selectively Enhances Memory Expected to Be of Future Relevance.
The Journal of Neuroscience. 31(5), 1563 - 1569.