1) Keeping away from sin, because the bad effects of sin result in a bad memory and the inability to retain knowledge. The darkness of sin cannot co-exist with the light of knowledge. The following words were attributed to al-Shaafa'i, may Allaah have mercy on him:
“I complained to [my shaykh] Wakee’ about my bad memory, and he taught me that I should keep away from sin.
He said that knowledge of Allaah is light, and the light of Allaah is not given to the sinner.”
Al-Khateeb reported in al-Jaami’ (2/387) that Yahya ibn Yahya said: “A man asked Maalik ibn Anas, ‘O Abu ‘Abd-Allaah! Is there anything that will improve my memory?’ He said, ‘If anything will improve it, it is giving up sin.’”
Ibraaheem ibn [sth. omitted] said, “You should chew resin gum, because it gives energy to the heart and gets rid of forgetfulness.” (From al-Jaami’ by al-Khateeb, 2/397)
Imaam al-Zuhri said: “You should eat honey because it is good for the memory.”
He also said: “Whoever wants to memorize hadeeth should eat raisins.” (From al-Jaami’ by al-Khateeb, 2/394).
May Allah (Swt) Improve all of our memory. Ameen.
Taken from from Islamqa.com
And Allah (Swt) knows Best