To date, my method for banishing the dreaded earworm is to sing a song I actually like in an attempt to "trump" whatever piece of pop fluff is driving me batty. Apparently scientists at Western Washington University, led by psychology professor Ira Hyman, have discovered a much better way.
The trick, it seems, is to solve puzzles -- sudoku, for example. But by far the most effective puzzle was five-letter anagrams.
The reason for this, the researchers say, is that puzzles engage the brain just enough. The abstract from the study "Going Gaga: Investigating, Creating and Manipulating the Song Stuck in My Head" states:
"The return of intrusive songs depended on cognitive resources: people reported that intrusive songs returned during low cognitive load activities, and we found that overloading the cognitive systems with challenging activities increased intrusive song frequency."
That is, if your brain isn't busy, you are far more likely to pick up an earworm; but if your brain is too busy or stressed out, you are also more likely to be plagued by a repetitive jingle. In order to have peace of mind, you have to engage your mind in the sweet spot: not too relaxed, but not too busy, either.
Earworms occur most likely if you start hearing a song in your head immediately after hearing it, or hearing a phrase that reminds you of it, a manifestation of the Zeigarnik Effect, whereby your brain will cogitate on an unfinished thought or task.
Hyman and his team surveyed 299 students, playing songs by Lady Gaga, Carly Rae Jepson, Beyoncé, the Beatles, Rihanna and Taylor Swift. The students rated the songs, then completed puzzle tasks, reporting back immediately after the puzzles, and then again 24 hours later on whether the song had returned. (Lady Gaga had the most addicting songs, according to the study.)
Interestingly, the researchers found that it's not even necessarily the most annoying songs that get stuck in people's heads the most, but songs they actually like. I hope that's not true for everyone, because it means I've profoundly misunderstood my own taste in music.
At any rate, it certainly would not hurt to download an anagram game or two on your smartphone in case of earworm emergency.