Memorizing is fine as far as it goes, but it doesn’t teach you to jam.
Anyone can get fooled when playing something they are not familiar with.
Examples: I played a great jam yesterday…all the musicians had 40+ years experience…a vocalist chose key of A for a song…we got done and the mando player (who is awesome good, sang tenor to the song, and has played with several well known bands) mentioned when the song was done that because we didn’t do the song in Bb he couldn’t pull off the Jimmy Goodreau break he had learned to it…
I played several songs yesterday that I'd never heard before without messing them up....how?...I recognised the "lead-ins" the other musicians were playing...this comes with experience and lots of listening, but eventually you can recognise the hints other musicians will give you so you can hit the next chord even if you don't know the song.....such as: if you are playing in key of G and playing the G chord....now you hear someone emphasise a G7th chord...it's a good bet the next chord is a C....This happens a lot and a good musician who recognises that someone doesn't know the song will use them to help lead you through the progression.
To me, jamming is more about ear training… recognising chord progressions (and chords) and having some “go to” licks that you can use in each chord. Specific melodies are great, but unless you learn to transpose them you’re stuck in one key when that song comes around. The chord progression is the foundation of the song…everything else builds upon that.
Examples: The first break I ever took in a jam on guitar was a simple “G run”/“Flatt Run” in the scale of each new chord in the song.
My first ever mando break in a jam was simply running the scale of each chord that came along.
I always suggest knowing the chords first, then work on the melody…Hint: the melody/lead break mostly lies in different variations of the notes you use to pay the chords…