Computers on spacecraft often have small memory, like a few MB. Wouldn't it be nice to put more memory into them？ Or is MB-level already enough? Also, which spacecraft has the largest memory?
Cosmic radiation represents a big threat to humans and to computing devices in space. Astronauts regularly report seeing flashes of light when they have their eyes shut. There are all kinds of things that just one cosmic ray can do to electronics. The generic name for these effects is single event effects. A cosmic ray might for example flip a bit (single event upset) or cause a bit to be frozen at zero or one (single event latchup). There are many other effects that can ensue from a single cosmic ray.
The computing industry is moving toward smaller and smaller die sizes for CPUs and memory. State of the art die sizes are 5 nanometers; even smaller die sizes are in work. A single cosmic ray would rip a big gaping hole in a CPU or memory constructed on the 5 nanometer scale. Computing machinery based on those very small dies would die a quick death in space. This is but one of the reasons why computers used in space are at least a decade behind state of the art, and the problem is getting worse. I'm working on a vehicle yet to be flown that uses computers that would not have been considered state of the art two decades ago.
One key factor for why spacecraft have such limited computing power and limited memory is that decisions regarding avionics are made very, very early in the spacecraft design process. It typically takes multiple years, and sometimes more than a decade, to progress from initial design to first flight. Those initial design decisions made years before first flight chose computing machinery that was deemed safe back then, and that typically means, and I'm trying to be nice here, extremely archaic junk. To add insult to injury, that extremely archaic junk is also extremely expensive. One can find better junk at a tiny, tiny fraction of the price in a yard sale. That yard sale junk would not however stand up to one single SEE.
For the second part of the question, which spacecraft has the largest memory, the answer is likely the International Space Station. But not the modules themselves!
About a decade ago, the station already had over 60 laptops, which is the type of computers in space that will be closest to the current state of the art. Looking up those laptop models listed, the station had at least a triple digit number of gigabytes of RAM.
Since the ISS is one of the very few spacecraft which continously receives hardware updates, the laptop fleet aboard has likely been updated since then, which brings the total amount of memory available even higher.
In space, there is more radiation (high energy particles) than on earth. These can damage RAM or flip the values of individual bits (working with corrupted data is often even worse than crashing).
So you can't just send some consumer-grade RAM chips up and expect them to work correctly. They may also need to be able to withstand a wide temperature range, have error-correction, and either be radiation-hardened and/or shielded. Search for "Radiation Hardened RAM" or "Rad Hard RAM".
Since they're specialized components, they don't come cheap (but are probably still a fraction of the cost of launching the device into space). Like every piece of hardware, they also have a size and weight, and space crafts have size and weight budgets. The later may be the even bigger constraint that cost.
With all these constraints, the designers of a craft/device are usually going to design with as few memory as necessary for the mission.
Modern computer RAM sizes are driven by the need to present large media files to a user — images, video, and so on. This isn’t needed at all on a spacecraft; the guidance computer isn’t watching Netflix. The critical functions of early spacecraft could be managed with a handful of kilobytes; more modern ones get by with megabytes rather than gigabytes. Processing of scientific data is done by Earthside computers, so only a moderate amount of memory is really required to buffer that data before transmitting it. As other answers note, RAM on spacecraft needs to be radiation-hardened and often must operate reliably at extreme temperatures, so it’s much more expensive than equivalent amounts of memory on a home computer, so you generally see much smaller memory sizes.
Aside from the issues of the harsh environment in space. It's also not necessary for specialised systems with dedicated capabilities e.g. military, space. Modern desktop systems are generalised and "waste" a lot of resources on being able to provide functions determined by software capabilities that is developed independently of the hardware.
I have worked on one of these in the past http://www.computinghistory.org.uk/det/16840/Ferranti-FM1600-B/ and they're still out there. It goes to show what can be achieved with 200kB of RAM coupled with dedicated hardware even in this day and age.
They aren't all so small. TESS has a 192 gigabyte solid state data recorder.
Another reason is that most small satellites use microcontrollers (mcu) instead of microprocessors (cpu), these mcu have a cpu inside but much more limited (some Mb or Kb) and have an internal ram also limited (about Kb) but they are very useful because when they are asleep they consume some micro watts! and they can also use radio communications, read all the sensors and activate any actuator (ion thruster, torquerod, reaction wheel, etc) and they can also contain real-time operating systems (instead of general purpose ones like windows, gnu / linux, etc) which is essential for critical applications, also these mcu are much cheaper than a general purpose cpu, you do not need a lot of ram unless you want to process a lot of data (analyze images, neural networks, etc)