“Obsessive–compulsive disorder (OCD) is a mental and behavioral disorder in which an individual has intrusive thoughts and/or feels the need to perform certain routines repeatedly to the extent where it induces distress or impairs general function” (Wikipedia).
Routines are called “compulsions”. These can be physical (like washing your hands or locking the door) or mental (usually more complicated). You do compulsions to appease the distress caused by your obsession (usually something you fear). And you do them repeatedly.
There are two known cures for OCD: antidepressants, and a special type of CBT called ERP. In a nutshell, ERP is this: you confront yourself with your fear/obsession without doing your compulsions. At first it's hard, then you start to habituate yourself and the obsession starts loosing its power.
I've been battling with OCD since adolescence. But recently I had an extreme bout, I was doing mental compulsions all day long. But then it became so complicated and messy that I didn't even know where to start, so I stopped doing my compulsions completely. At first I had an extreme sense of malaise, but with time it became easier and easier. This is ERP without doing ERP. And it works, I'm now nearly OCD-free.