“Is it necessary to remember what you improvise?”
I get asked this question a lot, and if you ever feel like you want to remember the great music you’ve just improvised but can’t, I know what you mean. I can't remember what I improvise either, although if I was composing I'd focus more on that and yes, remember 4 bars at a time.
But in general, it's the same situation for everyone. I don't think that Herbie Hancock or Keith Jarrett can remember their improvs either. And they don't want to. That's the nature of improvisation. It's like trying to remember word-for-word what we said to someone in conversation. After the event, it all goes "to the wind." That's the beauty of it.
At the same time, I know what you mean, and this is more along the lines of composition and there are two basic ways to go about it:
1. Improvise something, as you said, and then immediately remember it and develop it into a composition. You can practice this skill by simply improvising short melodic fragments and then repeating them, to improve our ability to recall them. Or, we can record our improvisations, as Miles Davis did, and later transcribe the parts we like and make them into compositions.
2. We can work slower, as classical composers do, and write down these melodic fragments as we go along and develop them on paper. This can work for any style of music, including jazz, blues, rock, pop, and hip-hop.
Overall, the beauty of improvisation is the very fact that it disappears as soon as we play it, and the beauty of composition is that we remember what we've played and the use our craftsmanship to shape the musical material into a polished piece composition. They're two entirely different, yet related, processes which can feed each other if we look at them in these ways.
I hope this helps, and good luck with your music!