Error with Debug - Allowed memory size exhausted

I am getting the following error when debug is set to true:

Fatal error : Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/xxx/vendor/defuse/php-encryption/src/Crypto.php on line 311

Any suggestions as to what might be causing this?

You may try increase your PHP’s memory_limit in php.ini.

Does not matter what I set it to. It works fine normally only issue when debugging

Make sure you don’t have indefinite loops. If you specify Start page, make sure the logged in user have permission to access, otherwise you have indefinite loop between the login page and the start page. Press F12 in browser and go to the Network panel to check the requests.