1. A computer-implemented method for improving memory usage for a computer program, comprising: (a) reading a trace that describes data accesses performed by the computer program; (b) analyzing the trace to discover data access patterns; and (c) building a grammar that represents repetitively occurring sequences of the data access patterns.