I've been getting this problem a lot and it's very frustrating. Sometimes, for no apparent reason, my MacBook will just freeze up or lag tremendously. The clock stops, apps stop responding, and it'll take a long time just to get a button to press. This usually happens when I'm watching a YouTube video in Safari.
When this happens, the memory pressure gets super-high in the Activity Monitor, and all "Safari Web Contents" and Safari itself are not responding. The Activity Monitor itself often freezes as well.
There is no high CPU usage when this happens. It's not overheating either. What could be the cause of this problem, and how can I prevent it from happening?