# Forget past outputs to free memory [duplicate]

While tinkering with a notebook that loads a large chunk of data in memory, I noticed that if I run it multiple times, the past chunks reside in memory. I understand that the reason (or one of) for which this happens is that the past output mechanism (%) keeps a reference to them, so they cannot be garbage collected.
• You can set $HistoryLength = 0 for instance. – b.gates.you.know.what Nov 20 '12 at 12:03 • – chris Nov 20 '12 at 13:17 • – Kuba Dec 10 '18 at 7:48 ## 1 Answer Use $HistoryLength = k

to keep the last k lines of input and output.