Oh, I've been able to memorize them right from the start. One of the first lines I ever learned was the main track to the videogame Doom, which originally of course wasn't written on bass, and wasn't even in the same octave, but still easily translated to bass. I retained that in my memory for over 5 years without playing it once.
To be fair, that was a pretty easy line, but my point is that I didn't exactly have to try and remember it. There's muscle memory and just generally memorization. I have that line in my head, but also in my fingers.
When were talking about more complicated stuff, or whole songs, then it's the same thing, but of course it takes longer to commit it to both muscle memory and normal memory. I learned the Muse song Psycho about 7 years ago. Took me days to commit it to memory, but it worked and I could actually tell that I was making progress with it. Once it's really in there, it tends to hold a couple years, and at the very least a couple months in my head.