Anti-Freeze & Smart RAM Optimizer

[Guide] Anti-Freeze & Smart RAM Optimizer with Desktop Launcher (Zorin OS Lite)

AI-assisted tutorial, please verify critical steps

This guide explains how to set up an automated, ultra-lightweight RAM optimization system tailored for Zorin OS 18 Lite (XFCE). It monitors your system memory and safely purges accumulated file caches when available RAM drops below a critical threshold.

To ensure total integration with your automated backups, the main script is stored inside the hidden .config directory, meaning it will be automatically backed up every week into your system architecture without any manual intervention.


📘 How This System Prevents System Freezes

On low-spec or older computers, RAM saturation is the number one cause of sudden system freezes. When memory reaches 100%, Linux triggers a brutal safety mechanism called the OOM Killer (Out Of Memory), which completely freezes the desktop for several seconds to forcefully terminate your active applications.

  • The Script's Role: It acts as a safety shield by intervening as soon as available RAM drops below 15%. It forces the system to flush obsolete file caches (like image thumbnails and web browsing residues) clogging up the memory.
  • Total Data Safety (sync): Before cleaning anything, the script triggers the sync command. This forces the PC to immediately write all temporary data and open documents onto your hard drive. Your active work runs absolutely zero risk of corruption.
  • 100% zRAM Complementary: While native zRAM compresses data from your running applications in the background, this script deletes garbage files from closed processes. Both tools work hand-in-hand to maximize global system responsiveness.

Step 1: Create the Optimization Script inside the Config Directory

Open your Terminal (Ctrl + Alt + T), copy-paste the following command block, and press Enter to generate the core script:

mkdir -p ~/.config
cat << 'EOF' > ~/.config/optimise_ram.sh
#!/bin/bash

# Retrieve the percentage of currently available RAM
MEM_DISPO_PCT=$(free | awk '/Mem:/ {printf "%.0f", $7/$2 * 100}')

# Critical threshold (15%)
SEUIL=15

if [ "$MEM_DISPO_PCT" -le "$SEUIL" ]; then
    # Secure active modifications to the disk, then purge unused system caches from RAM
    sync && echo 3 > /proc/sys/vm/drop_caches
fi
EOF

Step 2: Make the Script Executable

Grant the system permission to execute the newly created file by running this command:

chmod +x ~/.config/optimise_ram.sh

Step 3: Schedule Invisible Background Surveillance Every 10 Minutes

To allow the script to clean memory autonomously in the background without opening windows or prompting for passwords, we inject it into the root system scheduler using the secure tee command block. Copy-paste this and press Enter (type your user password when prompted):

(cat /etc/crontab 2>/dev/null; echo "*/10 * * * * root /bin/bash $HOME/.config/optimise_ram.sh") | sudo tee /etc/crontab > /dev/null

Step 4: Create a "Boost RAM" Flash Button on the Desktop

If you are about to launch a heavy piece of software and want to clear out your system memory immediately without waiting for the 10-minute automated cycle, you can use a manual trigger. This block generates a sleek desktop launcher with the modern Lightning Bolt / Energy icon style:

cat << 'EOF' > ~/Desktop/Boost_RAM.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name=Boost RAM
Comment=Force an immediate manual optimization of the system RAM
Exec=xfce4-terminal -e "bash -c 'echo \"Checking RAM status manually...\"; sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches > /dev/null; echo; free -h; echo; read -p \"RAM optimized successfully! Press Enter to close...\"'"
Icon=xfpm-ac-adapter
Terminal=false
Categories=System;
EOF
chmod +x ~/Desktop/Boost_RAM.desktop

🚀 Final Activation

Minimize your windows and look at your Desktop. You will find a brand new Boost RAM launcher icon featuring a clean lightning bolt design.

Double-click it for the very first time. Zorin OS Lite will prompt a security pop-up: simply click "Mark Executable" to permanently activate the shortcut. You're good to go!