Masturbation is generally not considered to have a detrimental effect on memory or cognitive function. During sex, cognitive function may be impaired due to the flood of neurotransmitters in the brain.