I've been in the lonely place you inhabit now and can say it passes. I promise you it does. It hurt likes hell, but you will be in a different place. Try to see the mind as a poorly functioning computer. Garbage in, garbage out. It's programmed that way. But we can change the programming.
When a specific person is living rent free in my head I say out loud: "Thank you for sharing _______, now get the f*ck out of here". I think the more I acknowledged my mind was spewing out garbage the easier it got to control it. I change the channel.
I jump into a book I like, watch TV, anything to divert the mind.
And having a reality check: while I was obsessing about ______, he certainly wasn't thinking about me. If he cared he would have changed. He cares about booze, it his the great love of his life.