There is a parable about a person that studies torah and forgets it: A group of men were once hired to fill up barrels. However the barrels had holes in them and as much as the workers would pour in would end up spilling out. The foolish workers said "since everything ends up leaking out of the barrels, why should we work so hard to fill them, since afterwords it all spills out?" The wise worker on the other hand said, "What do I care, they are paying me by the day, and regardless they will not hold back my salary since I am already hired fro a certain amount of time, what difference does it make to me if it spills out of the barrels?" So too a person that forget what he learns, his compensation will also not be held back for each day he studied.
Also know, that in the future world they remind each person everything he studied, although he forgot it. Even people that hear the Torah of the True Tzadik and do not understand it, in the Next World they will understand it. This is because the main reason of Torah study is for the soul, so in the Next World the souls will be experts and grasp well the Torah that a person studied and heard in This World. Fortunate is a person who passes all his days immersed in much Torah study and service of Hashem.
(Sichos Haran 26)