A listing that fails with an out-of-memory error, or takes so long that the request is cut off, is loading more than it shows. In order:

  1. No limit on the query. A $_query->findBy() without a limit, or a getter that returns every child of a large parent, loads every record into memory, however few the page prints. Pass a limit, or paginate.
  2. Related records read for every row. Each record a template touches stays in memory until the request ends, so a long list that reads relations on every row holds the list and all of its relations (a relation in a loop).
  3. Loading the records behind search results. getRecord() on every result of a search loads the whole record per row. Render from the indexed fields instead (what the template receives).
  4. A list that grew. It worked at launch with fifty records and fails with five thousand. Any list that can grow needs pagination, or a search view, which pages by default (filtering a listing).

On a development environment the error page shows the template and line; on production, look under Template Errors in the admin. Fix the query, not the limit: a page that needs more memory today will need more again next year.