Pre-treat any stains. Blot the stain with a damp sponge or cloth with a mild household detergent on it, like dish detergent. Use a gentle circular motion to remove as much of the stain as possible. Use pet-stain remover or carpet cleaner on more difficult stains.
Vacuum the memory foam thoroughly.
Place the memory foam in the bathtub with a shower head that can be used to rinse the foam, like a shower massage. Put larger pieces like mattresses on a tarp outdoors near a water source with a hose. Take care not to let the memory foam rest on the dirt or grass.
Fill a spray bottle with two parts warm water to one part mild detergent. Spray the memory foam thoroughly, covering all surfaces. Let sit for about a half an hour.
Rinse the surface of the memory foam. Try not to saturate the material. Carefully squeeze out extra moisture. Don't twist the foam.
Air-dry the foam for several days away from direct sunlight. Make sure large pieces of foam don't lose their shape while drying. Use a hair dryer on smaller articles made from memory foam to speed up the drying process.