Before fixing, diagnose the root cause. This error is rarely random.
or a mismatch between the software you are trying to flash and the physical hardware of your device
Were you trying to or restore a bricked device ?
If you have completed all these steps and the red bar still fails with the RAM exception, you must accept the sad truth: your device has a physical RAM failure. At this point, seek professional micro-soldering services for a CPU/RAM reball or replacement.