Sometimes in real time mode after I stop singing or playing a note, the note continues to play through the speaker.
There may be a feedback loop between the microphone and speaker. Use a unidirectional microphone.
Use a headset or earphones instead of speakers.
If you are playing an instrument that contains a pickup, such as an electric guitar, feed the output of the pickup into your computer instead of using a microphone.