All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
said: “Al-Qurtubi said: If someone is able (to get married) and fears harm for himself and his religion by remaining single, in a way that this harm is not removed from him except by marriage, then there is no difference of opinion that it is an obligation for him to get married.”
Also, Ahkaam Al-Quran authored by Al-Qurtubi reads: “The scholars have split into three different opinions about this: our scholars [i.e. the scholars of the Maaliki Mathhab] say that the ruling in this regard differs according to the believer's situation regarding fearing hardship, impatience, strength to be patient and absence of fear of hardship. If he fears ruin in his religion or worldly matters or in both, then marriage is inevitable.”
On the other hand, masturbation is forbidden and it results in many harms to the Muslim in his religious and worldly matters, so you must give up this evil habit. A Muslim should do everything that would help him preserve his private parts and avoid what arouses his desires, and do anything to extinguish them, like fasting, lowering the gaze and keeping good company.
For more benefit, please refer to Fataawa 81150, 81853 and 84026.
Allaah knows best.