When you hit play for the first time in a comp, think of it as a race between the RAM preview and the playhead (a race where the playhead can never truly win). If the composition is simple, the RAM preview creation (the green line) will outpace the playhead, and you'll get real-time (or very close to real-time) playback. If your composition is complex, playback will be slow, down since the playhead cannot surpass the RAM preview. Once After Effects has created the RAM preview, you'll usually get real-time performance on a second play-through. That is, unless, you make a change to any parameter on any layer in your comp and then the RAM preview disappears and the process begins again, since even the tiniest changes causes After Effects to have to recalculate the altered frames all over again.

RAM previews will eat up as much RAM as you allocate to After Effects (you can control this in Preferences, under Memory). If you are working in many compositions at a time within a project, AE will continue to create RAM previews as you play each composition. Eventually, when AE fills the RAM cache, the oldest cached frames will be purged automatically. For example, you might create RAM previews of Compositions 1, 2, 3, and 4, but when you reach Composition 5, it may automatically purge the RAM preview from Composition 1. It depends on the length and complexity of your comps and how much RAM you have. This is one of the many reasons After Effects loves RAM!

Most of the time, you don't have to overthink this stuff. It just works (usually). But if you've devoted 30 of your 32GB of RAM to After Effects and your Global RAM Cache is full, what happens when you suddenly need to open Pro Tools or DaVinci Resolve? There's not much RAM left over for them.

There are two ways to get RAM back manually. The first is the most obvious and the one most people think they need to do - quit After Effects. Duh. You can force AE to give up its hold on RAM without quitting, by running a very simple command: Purge -> All Memory (found under the Edit menu).