Cc1plus.exe: out of memory allocating 536875007 bytes

I am trying to compile Arduino code, but my compiler seems to run out of memory. I’ve googled this issues and others have had it with Qt. But I’ve found no solution for PlatformIO.

512MByte is not much when I have 64GByte available.

How can I solve this?

The error I get:
cc1plus.exe: out of memory allocating 536875007 bytes