we listen to music more and we can almost always find the exact version to replay again and again. before this technology existed, when only live music existed, what did people do if it got stuck in their head? just hum it until they forgot it? if they were likely to never hear the same song again.
Before mass media it was harder for someone to become inundated with tunes: music was manually produced, sung or played live. So, the average person would not be trying to memorize a playlist of thousands of songs.
However, there were "ear worms", catchy melodies that became popular. We know this because once those melodies became popular, musicians would use them for other things. In medieval music they were called "contrafacta", and a very famous one is the song L'Homme Armé, that appeared anonymously around the time of the fall of Constantinople to the Turks in 1453. It was then picked up and used as a melody for the mass by composers like Guillaume Dufay.
Similarly, at a market in England , say in the 17th c. there would likely be someone selling ballads. Written on various topical themes or humorous narratives, they're now generically called broadside ballads, as they would be printed on single long sheets of paper, and draped over the arm of the person hawking them. There would not typically be music written out under the lyrics: instead, at the top would be a note as to the melody, like " to be sung to the burden of Greensleeves " or " to the burden of Packington's Pound" . As there would be no point in setting the ballad to something obscure, a surviving broadside ballad gives us an indication as to whether a tune was popular.
Another clue comes from the musical game of theme and variation that would be a standard form for western musicians of the Renaissance and Baroque. A lutenist would be asked to do variations to show off her technique, and of course she would tend to use popular tunes for her themes. Just as Greensleeves and Packington's Pound would be common for English broadside ballads, they are commonly found in old English lute books as well.
But you also raise the point about how anyone could remember a lot of tunes? They could of course sometimes be able to write them down. But music written on paper was an expense, not always practical, so there was also the Guidonian Hand, a system of memorizing a musical part by referring to different parts of the hand. You can see some singers doing it here. Coincidentally, they're singing L'Homme Armé
Lastly, tunes got memorized better if they had names. If you take a look at traditional Irish music, you'll notice striking names like My Honest Dear Neighbor I Never Killed your Cat, and traditional Appalachian fiddle tunes can have names like Hog Went for the Fence Yoke and All. Makes them harder to forget.