https://en.wikipedia.org/wiki/Boolean_satisfiabili... explains the SAT problem that products like Composer internally need to handle. Specifically how to handle an unknown number of recursive constraints (every package you include includes other packages with specific constraints) is eventually a brute force problem that boils down to evaluating hundreds of thousands or even millions of possible solutions to the original set of constraints.
The solver needs a ton of RAM and CPU power to do that work, and stores the result of its hard work in the lock file. Using the lock file, any machine you want to deploy to can reproduce the solution by just installing what's in the lock file. In that scenario Composer barely uses any RAM at all because indeed it's not doing any hard work internally.
mmap() failed: [12] Cannot allocate memory
mmap() failed: [12] Cannot allocate memory
PHP Fatal error: Out of memory (allocated 904929280) (tried to allocate 20480 bytes) in phar:///home/ubuntu/print-press/composer.phar/src/Composer/DependencyResolver/Pool.php on line 205
Fatal error: Out of memory (allocated 904929280) (tried to allocate 20480 bytes) in phar:///home/ubuntu/print-press/composer.phar/src/Composer/DependencyResolver/Pool.php on line 205