Zapan: When string functions crash depending on random conditions, such as the size of the nexus, then internal memory is most likely overwritten. It can be a bug in the script, or a damaged file with wrong internal pointers. This project will behave unstable.

Generally, if something bad happens in a project, increasing the memory in the hope that it will then crash less often is the wrong strategy. Better try the opposite, establish some worst case condition where is always crashes. This way you'll find the reason more easily by temporarily eliminating parts of your code.