Memory is the residue of thought.

From An Essay Concerning Humane Understanding:

Attention and repetition help much to the fixing any ideas in the memory. But those which naturally at first make the deepest and most lasting impressions, are those which are accompanied with pleasure or pain. The great business of the senses being, to make us take notice of what hurts or advantages the body, it is wisely ordered by nature, as has been shown, that pain should accompany the reception of several ideas; which, supplying the place of consideration and reasoning in children, and acting quicker than consideration in grown men, makes both the old and young avoid painful objects with that haste which is necessary for their preservation; and in both settles in the memory a caution for the future.