There are several points in your code’s execution journey where the amount of available memory maybe important. Learn how to get that value.
Observing your code running out of memory after a few iterations? Memory leaks caused by JSON objects might be the culprits. Learn how to fix them.