Code stops after some time using delay

You would have to look at the compiled code to see if there is any difference.

If you find the approach you have taken is indeed successful it would be important to switch back to the const int version of the code to see if it breaks again.

If you can turn the problem on and off with argument for delay(), then you have possibly discovered some sort of compiler bug which deserves further investigation.