Actually true playing by ear does not really involve memorizing anything. It is a combination of experience, musical knowledge and a skill, acquired or natural.
Top ear players don’t need to have seen notes, or even have played the song before.. Unless it has a difficult to remember melody, or an unusually complex chord structure I can just hear it in my head and play it in real time., and not just on an easy play chord /melody mode like an arranger. But fully improvising a complete solo arrangement across both hands on a conventional keyboard.
Of course if I practice the piece I might play it better, but on a simple song, it would still be good enough first time. And I might glance at a lead sheet if it is a song where I am not too sure I remember the tune exactly. But you could throw at me a song like for example My Blue Heaven, which I know so I could hum the tune, but don’t think I have ever played, and I could play it immediately especially if I choose a simple key., without seeing music, chords or even spending time thinking. I just play and it all happens naturally. But then so could nearly all of the experienced musicians I have played with over the years. And many of them much better than me, in any key. That’s what playing by ear is about.
Mike