Not sure what you want to achieve with that, but if you want to stop the graphical environment, you can get that with:
systemctl isolate multi-user
(this is the equivalent of init 3 in the old sysvinit system)
To get back your graphical environment, execute:
systemctl isolate graphical
(this is the equivalent of init 6 in the old system)
Of course you should run these commands in a tty (Usually something like CTRL+ALT+F3 from the graphical environment). Also add sudo if you log in to the tty with a normal user.
It will free up some RAM, because logging out of the desktop environment or stopping the graphical session altogether will flush buffers and drop some cache, and a lot of stuff will not be loaded in RAM anymore.
However, there should be no need for this, as the Linux kernel is very good at managing memory — actually, Linux manages memory probably better than any other operating system kernel out there.
What you need to understand is that a lot of the memory in use is simply cache. This means that it’s disposable memory content, only kept in virtual memory for convenience, so as to improve performance — it is faster to load something already in RAM than to load something from the drive.
When more memory is needed, the kernel can do two things, i.e. paging out stuff to the swap device, and releasing some of the memory used as cache.
The bottom line of course, is that we’re dealing with an XY problem. You are asking about a proposed solution to a problem, rather than about the problem itself.
Maybe you should tell us why you want to temporarily free up RAM? If it’s because of potential memory corruption by cosmic radiation or electromagnetic fields, then this approach won’t work. If this is your concern, then you should shut down the computer and let it sit powered down for about 10 to 15 minutes before booting back up.
Again, tell us about the problem, not about what you think the solution would be to some problem that you’re not sharing with us.
Thanks everyone for an incredibly helpful and clear explanation of how CPU and RAM consumption function together.
I was running Conda and it was eating my CPU and RAM , I didn’t know I can give limited thread and downgrade to older version , since all i needed terminal to access conda I thought if I just disable desktop environment and enable it later
it still isnt clear why you thought nuking the DE was the resolution, i’ve no idea what conda does. but if this was on the lines of having maximum available memory to run your stuff, and you think plasma resource usage is too much, try using alternate light weight window-manger. there are plenty available through official repos. Window manager - ArchWiki
in case you need quick memory cache drop after an exhaustive op, you can use;