Issue
Your code may run on different dyno types and sizes so you want to dynamically determine the processes's memory limit at runtime.
Resolution
The value of /sys/fs/cgroup/memory/memory.limit_in_bytes
will represent the amount of memory available:
$ heroku run 'cat /sys/fs/cgroup/memory/memory.limit_in_bytes' --size standard-1x
536870912
$ heroku run 'cat /sys/fs/cgroup/memory/memory.limit_in_bytes' --size standard-2x
1073741824
$ heroku run 'cat /sys/fs/cgroup/memory/memory.limit_in_bytes' --size performance-m
2684354560
$ heroku run 'cat /sys/fs/cgroup/memory/memory.limit_in_bytes' --size performance-l
15032385536