$HistoryLength specifies the number of previous lines of input and output to keep in a Mathematica session.
The default setting for $HistoryLength is Infinity.
Values of In[n] and Out[n] corresponding to lines before those kept are explicitly cleared.
Using smaller values of $HistoryLength can save substantial amounts of memory in a Mathematica session.
See The Mathematica Book: Section 2.13.1.
See also: $Line.