There is literally no greater joy in life than making music. I'm a student now, and currently more a performer than a composer, but the composition process is a mix of understanding what rules to follow to make something enjoyable or catchy or inspire a certain feeling, and knowing how to work in and around the rules—breaking them whenever it suits the piece—to get something across. There's a mix of analytical and emotional thought that goes into writing, and you see this kind of overlap through most of music. When you play or sing, you're managing several factors at once, and you can't let any of them slip.
No one thing makes music enjoyable, but the main things are knowing what you're doing and having something to say with it.
Anyway yeah I have the same problem as OP from time to time, I can only keep something in my head after I've audiated it for very long if I can focus on keeping the line in my head. I have to write it down or record the intervals or something before it slips away.