# Find out what a program keeps in memory

Read the plan report dmog explain prints, to learn how a program reads its input and what it holds while it runs.

Before running a program over a large document, you want to know whether its memory grows with the document. `dmog explain` prints the program's plan without running it.

## Print the report

Name the program:

```console
$ dmog explain table.alc
export: table-from-json

Source reads:          1
Protocol:              JsonEvents/1 → Stream<Selected> → Stream<Value> → TableRows/1 → Text
Selection:             shared prefix matcher, two capture routes
Duplicate members:     rejected in captured scopes (DUPLICATE_MEMBER)
Capture:               .response.metadata.fields, capped at max_metadata_bytes
Row capture:           one .response.payload.deep.records[*], capped at max_record_bytes
Retained state:        the table's columns once bound, at most max_columns of them, no deeper than max_depth, capped at max_metadata_bytes
Output order:          selection order: completed matches, in source order
Ordering contract:     each item before its outputs
Contract verification: runtime
CSV quoting:           always (the host's renderer)
External storage:      disabled

Guarantee:
  Memory is independent of the number of rows under the configured
  depth, capture, metadata, scalar/key and output limits: the state the
  step returns is capped at max_metadata_bytes. What one step computes
  is the program's, bounded by the host's abort flag.

Qualification:
  A later error can occur after earlier output has been written.
```

## Read the report

The lines that answer the memory question are these:

- `Source reads` is how many times the input is read. One read means the document streams through once.
- `Capture` and `Row capture` name the parts of the document the program holds, and the limit that caps each.
- `Retained state` is what the program keeps between records.
- `Guarantee` says what memory does not grow with. Here it does not grow with the number of rows.

`Qualification` says what the guarantee leaves open. Here a failure late in the document can come after earlier rows were written.

## What to watch for

The report describes the plan, not one run of it, so it is the same for every document. Every field of the report is defined in [the alchemy language reference](https://github.com/tabnas/alchemy/blob/main/docs/language.md#explain), on GitHub.
