«حفظتُ» reports that memorizing occurred without naming the thing memorized. «حفظتُ القرآنَ» adds a direct object and identifies the target of the activity.
The object is useful when the hearer needs to know what was memorized. If the surrounding conversation already identifies the object, omitting it may be more appropriate.