To study data placement on memory hierarchy, we present a model called reference affinity. Given a program trace, the model divides program data into hierarchical partitions (called affinity groups) based on a parameter k, which specifies the number of distinct data elements between accesses to members of each affinity group. Trivial solutions exist for the two ends of the hierarchy. At the top, when k is no less than the data size, all program data belong to one affinity group. At the bottom, when k is 0, each element is an affinity group.We present two theoretical results. The first is the complexity. We show that finding and checking affinity groups are in P when k = 1 and k = 2. When k = 3, the checking problem is NP-complete, and the finding problem is NP-hard. The second is the uses. We show that reference affinity captures the hierarchical data locality from the trace of a hierarchical computation. As additional evidence, we cite empirical results for general-purpose programs.