He has fallen into sin and he is afraid that he may forget knowledge and Quran
Question

Does falling into sin mean that one will inevitably forget knowledge and Quran? I fall into sin but I do not persist in it, rather I feel deep regret after falling into sin and I am very afraid that my falling into sin will lead me to forget what knowledge I have acquired. To be very frank, this sin involves looking at haraam things and that which accompanies it, namely masturbation. But by Allah, I only do that when I am in a state of stress and depression, and I find myself doing that when looking at pictures or videos with which my brothers fill the computer. My problem is that Allah has blessed me with physical strength and I want very much to get married, but I do not have any money. I fast every Monday and Thursday and three days of every lunar month. I hope that you will reply and not leave me like this .
Praise be to Allah.Firstly:
Sin has a bad effect on the one who commits it. Ibn al-Qayyim (may Allah have mercy on him) has mentioned a number of its bad effects, some of which we will mention here:
1-     Deprivation of knowledge. Knowledge is a light which Allah instills in the heart, but sin extinguishes that light. When al-Shaafa’i sat before Maalik and recited to him, he was impressed with what he saw of his deep knowledge, intelligence and understanding, and he said: I see that Allah has filled your heart with light, so do not extinguish it with the darkness of sin.
2-     Deprivation of provision. In the Musnad of Imam Ahmad it is narrated that Thawbaan (may Allah be pleased with him) said: The Messenger of Allah (peace and blessings of Allah be upon him) said: “A man may be deprived of provision because of a sin that he commits.” Also narrated by Ibn Maajah (4022) and classed as hasan by al-Albaani in Saheeh Ibn Maajah.
3-     Alienation between the sinner and his Lord, and between him and other people. One of the salaf said: If I disobey Allah, I see that in the attitude of my mount and my wife.
4-     Life becomes difficult for him; he does not try to do anything but he finds the way barred to him or it is very difficult; by the same token, things become easier for the one who fears and obeys Allah.
5-     The sinner finds darkness in his heart, which he senses as he senses the darkness of night. The darkness of sin affects his heart as the darkness of night affects his vision, for obedience is light whilst disobedience is darkness. The more the darkness increases, the greater his confusion becomes, until he falls into innovation, misguidance and things that will doom him to Hell, without realizing it, like a blind man who goes out in the darkness of the night, walking alone. This darkness increases until it appears in his eyes, then it increases until it dominates his face and becomes a “blackness” that is visible to everyone. ‘Abd-Allah ibn ‘Abbaas said: “Good deeds produce radiance on the face and light in the heart, increased provision, physical strength, and the love of others. Bad deeds produce ‘blackness’ in the face, darkness in the heart, physical weakness, inadequate provision and the hatred of others.”
6-     Deprivation of doing acts of worship. Even if a sin is not punished, it prevents a person from doing acts of worship, which are replaced with acts of disobedience, and it blocks the path to other acts of worship, then the sin cuts off the way to a third act of worship and a fourth and so on. So the sin prevents him from doing many acts of worship, each of which would be better for him than this world and everything in it. This is like a man who eats something that causes a lengthy sickness and prevents him from eating food that is better than it. And Allah is the One Whose help we seek.
7-     Sin generates more sin, until it dominates a man and prevents him escaping from it.
8-     Sin weakens the heart, reducing its will to do good and increasing its will to sin. It weakens the will to repent until there is no will to repent in the heart at all. This is one of the worst of diseases and the closest to doom.
9-     It robs the heart of repugnance towards sin, which then becomes a habit; he does not feel any discomfort at the thought of people seeing him or talking about him.
Secondly:
The fact that you feel under stress and are looking for a way out is a sign of sincerity in sha Allah, and is the beginning of repentance, by Allah’s leave.
Each one of us needs to examine himself and sincerely resolve to engage in “jihad al-nafs” against his self that is inclined towards evil, and equip himself with the right “weapons” for that.
We will give you some pointers which we ask Allah to make beneficial for us and for you:
1-     Pray to Allah (du’aa’) and beseech Him. Remember that Allah will not let down the one who calls upon Him. Allah says (interpretation of the meaning): “And your Lord said: “Invoke Me [i.e. believe in My Oneness (Islamic Monotheism) and ask Me for anything] I will respond to your (invocation)” [Ghaafir 40:60]. Turn to Allah in supplication and seek out the times and places where du’aa’ is answered, such as when prostrating, in the last hour of the day on Friday, and during the last third of the night when our Lord descends to the lowest heaven and calls out, “Is there anyone who is calling, that I may respond to him? Is there anyone asking for forgiveness, that I may forgive him?” Do not despair of a response, for Allah is Ever close and responds to the call of the one who is in distress when he calls upon Him, and He grants relief from distress.
2-     You should do more acts of worship, as Allah says (interpretation of the meaning): “Verily, the good deeds remove the evil deeds” [Hood 11:114]. Seek help through prayer, for it is as Allah says (interpretation of the meaning): “Verily, As‑Salaah (the prayer) prevents from Al‑Fahsha’ (i.e. great sins of every kind, unlawful sexual intercourse) and Al‑Munkar (i.e. disbelief, polytheism, and every kind of evil wicked deed)” [al-‘Ankaboot 29:45].
3-     You should be keen to increase your knowledge of Allah, may He be glorified and exalted, by learning His names and attributes, and by thinking about the creation of the heavens and the earth. By doing that, a person will become shy before Allah. As one of the salaf said: Do not think of the smallness of the sin, rather think of the greatness of the One Whom you have disobeyed.
4-     Remember that the path to Paradise is difficult and requires effort and patience. Allah says (interpretation of the meaning): “As for those who strive hard in Us (Our Cause), We will surely guide them to Our paths (i.e. Allah’s religion — Islamic Monotheism). And verily, Allah is with the Muhsinoon (good-doers)” [al-‘Ankaboot 29:69].
5-     Think about the benefits of lowering your gaze and make that your motive; that will help to ward off the whisperings of the nafs and the promptings of the shaytaan. These are some of the benefits, which we will list for you so that Allah may benefit us and you thereby:
·        Lowering the gaze is obedience to the command of Allah, as Allah says (interpretation of the meaning): “Tell the believing men to lower their gaze (from looking at forbidden things)” [al-Noor 24:30]. Obedience to the command of Allah leads to the greatest happiness in this world and in the Hereafter.
·        It purifies the heart and soul, and one’s deeds.
·        It prevents the poisoned arrows from having any effect, for a glance is one of the poisoned arrows of the shaytaan.
·        The compensation for lowering the gaze is the sweetness of faith in the heart.
·        One attains truthful insight by means of which one can distinguish between truth and falsehood.
·        It rids the heart of the pain of regret, for the one who lets his gaze wander will always feel regret.
·        It fills the heart with happiness, joy and light that is greater than any pleasure derived from looking.
·        It frees the heart from being a prisoner of desire, for the true prisoner is the one who is the prisoner of his whims and desires.
6-     Keep yourself busy with useful and beneficial things, attending lessons and listening to lectures, for there is nothing more harmful to a person than spare time and being alone.
7-     Look for righteous friends who can help you to obey Allah, for the shaytaan is close to the one who is alone, but he is further away from two, and the wolf only eats the sheep that has strayed from the flock.
8-     Avoid the things that provoke desire in you, such as looking at haraam images, for as well as being haraam in and of itself, it also leads to other haraam things.
9-     Masturbation is a haraam action, and is not befitting for a decent person. There is a great deal of evidence to show that it is haraam, which you will find in the answer to question no. 329.
Hasten to repent to Allah, and fear His wrath and anger. Remember that knowledge and righteousness are a blessing from Him, and He may become angry with the one who disobeys Him, and withdraw those blessings from him, as He says (interpretation of the meaning):
“And recite (O Muhammad) to them the story of him to whom We gave Our Ayaat (proofs, evidences, verses, lessons, signs, revelations, etc.), but he threw them away; so Shaytaan (Satan) followed him up, and he became of those who went astray”
[al-A’raaf 7:175]
Keep in mind the greatness of Allah, and remember that He is always watching you, for nothing about you is hidden from Him.
Imagine yourself sitting with your righteous brothers and refraining from sin out of shyness towards them; so do not regard Allah as the least significant of those who are watching.
The Prophet (peace and blessings of Allah be upon him) advised a man among his companions, saying: “I advise you to feel shy before Allah as you feel shy before a righteous man among your people.” Narrated by al-Tabaraani and by al-Bayhaqi in Shu’ab al-Eemaan; classed as saheeh by al-Albaani in Saheeh al-Jaami’ no. 2541.
We ask Allah to ward off evil from you and to help you to obey Him and please Him.
And Allah knows best.