When your Mac’s memory fails or is improperly connected, you can get what is called an Error 50 code displayed on your Mac, even as it restarts itself several times. There won’t be a patter to this restarting and it will just happen suddenly, over and over again, until you fix the problem.
This issue is discussed in detail at http://www.whyismymacsoslowallofasudden.com/, a site dedicated to help you speed up your Mac and also to fix various critical issues, like your Mac restarting with an Error 50 code.
First, you must check if your RAM has a loose contact. The only way to do this is to open up the back of your Mac and physically remove the RAM chip. Then, you must install it back again. If while removing you see that the RAM is not clamped down properly or has a jiggle to it, it definitely means that your RAM chip wasn’t inserted properly the first time. It can also come loose when you throw your Mac around a lot, like how you do when you usually haul your MacBook from work to home and elsewhere.
If the faulty RAM installation was present, your Error 50 problems will go away immediately, now that your Mac’s CPU has a stable connection with the Mac’s RAM. If it doesn’t go away still, it could mean that your Mac’s RAM has finally given up in the hardware sense. In other words, the circuit within the RAM chips might be failing. It is quite possible for RAM chip to work intermittently, working fine for several hours before crashing suddenly, for no apparent reason. Run an Apple diagnostic test to check your RAM and see what the report says. If it says that RAM is normal, you also try doing a safe restart on your Mac to see if the crashing was caused by improperly installed Mac OS.