Zend certified PHP/Magento developer

Magento 2 Memory size problem

I call for your help to solve a big problem on my Magento 2 site. Every night this one crashes due to a memory problem. Putting a memory limit at -1 is not the solution in my case otherwise it bugged my entire server after 48 hours.
Here are the error messages :

2021/07/24 07:21:10 [error] 29075#29075: *352922 FastCGI sent in
stderr: “PHP message: PHP Fatal error: Allowed memory size of
2147483648 bytes exhausted (tried to allocate 134217736 bytes) in
www/vendor/magento/module-csp/Model/Collector/DynamicCollector.php
on line 31” while reading response header from upstream, client:
127.0.0.1, server: XXX, request: “GET /ophangaccessoires/ophangdraad-en-haken.html HTTP/1.1”, upstream:
“fastcgi://127.0.0.1:9000”, host: “XXX” 2021/07/24 07:36:36
[error] 29075#29075: *353038 FastCGI sent in stderr: “PHP message: PHP
Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried
to allocate 20480 bytes) in
www/vendor/magento/framework/Serialize/Serializer/Json.php
on line 37” while reading response header from upstream, client:
127.0.0.1, server: XXXX, request: “GET / HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “XXX”,
referrer: “https://XXX/”

I have to clear the cache to fix the problem when my site crashes

Thank you for your help 🙂