Based on your description, if your laptop has half of its RAM available but is still heavily using swap and shutting down, the issue is likely not related to insufficient memory. This behavior is highly unusual and points to a more specific problem.The most probable causes are:Memory leak: One or more of your running applications, or even a driver, could have a memory leak. A memory leak is a programming error where an application fails to release memory it no longer needs. Over time, it can consume all available RAM, forcing the system to use swap and eventually leading to a crash.Faulty RAM stick: While less common, one of your RAM modules could be defective. A faulty RAM stick might cause intermittent errors and crashes without showing up as fully used memory, as the system may be trying to avoid the bad section of the RAM. The laptop might shut down as a safety precaution.Overheating: Even with half-empty RAM, if your CPU or GPU is under heavy load (which is common in AI workloads) and the cooling system is not working correctly, it could cause the system to shut down. This would not directly explain the swap usage but could be the reason for the shutdown.How to Solve the ProblemIdentify the Memory LeakUse the htop command again, but this time, pay very close attention to the RES (Resident Memory Size) and VIRT (Virtual Memory Size) columns.Monitor these values for a few minutes. If you see the memory usage of a specific process constantly increasing without ever decreasing, you've likely found the memory leak.Once identified, you should close the application. If it's a critical application for your work, you may need to update it or look for an alternative.Test Your RAMUbuntu has a built-in tool for this, but the best way is often to use a dedicated memory testing program. You can install Memtest86+ to create a bootable USB stick for a thorough test.Restart your laptop, boot from the Memtest86+ USB, and let the tests run for several hours. This will check every part of your RAM for errors. If it finds any, you'll need to replace the faulty RAM stick.Check for OverheatingInstall and use lm-sensors to monitor your CPU temperature.Bashsudo apt update
sudo apt install lm-sensors
sensors
Run a demanding task (like a small AI model training script) and watch the temperature. If it goes above 90°C (194°F), it's likely a thermal issue. In this case, you may need to clean the cooling vents, replace thermal paste, or check if the fan is working properly.Given the context of your AI research, a memory leak is a very plausible explanation, especially if you're working with custom scripts or specific libraries that may not be well-managed. Finding and fixing this will be your most important step.