Your WordPress Site Is Bleeding Memory — Here's How to Stop It
Source: Dev.to
The hidden cost of a page load
When a visitor loads a page, WordPress does a lot behind the scenes:
- PHP starts up and loads all the WordPress core files.
- Every active plugin gets loaded — even if it isn’t needed for that page.
- Your theme is loaded.
- WordPress runs a series of database queries.
- All your hooks and filters fire.
- The page is assembled and sent to the browser.
Each step consumes memory and time. The more plugins you have, the larger the overhead.
PHP has a memory limit (often 128 MB or 256 MB). Exceeding it triggers a fatal error such as:
Fatal error: Allowed memory size of 134217728 bytes exhausted
Even if you stay below the limit, a page that uses 100 MB of memory will feel noticeably slower than one that uses 30 MB.
What uses the most memory?
- Page builders (Elementor, Divi, WPBakery) – 50–80 MB per request.
- WooCommerce with large product catalogs.
- Plugins that load large libraries they rarely need.
- Badly written custom code.
Database bloat
WordPress stores almost everything in the database: posts, settings, user info, plugin data. A fast site might run 20–30 queries per page, while a poorly optimized one can run 500+ queries on a single request.
Typical sources of excess queries:
- Unoptimized plugins.
- Themes that repeatedly query the same data.
- Custom code that isn’t efficient.
- Too many plugins doing overlapping work.
Why the database grows
- Post revisions – Every edit creates a new row. Ten thousand+ revisions can accumulate.
- Orphaned data – Deleting posts or plugins sometimes leaves behind rows that reference non‑existent objects.
- Stale transients – Some plugins create transients that never expire or aren’t cleaned up.
- Auto‑drafts and trash – Items sit in the database for up to 30 days.
- Orphaned cron jobs – When a plugin is removed, its scheduled tasks may remain, trying to run code that no longer exists.
Orphaned cron jobs
WordPress’s scheduling system (wp‑cron) runs background tasks such as publishing scheduled posts, sending emails, or cleaning up data. If a plugin that registered a cron job is deleted, the job can linger indefinitely, wasting resources and sometimes causing errors. Sites have been found with 100+ orphaned cron entries from plugins removed years ago.
How to get visibility
You can’t fix what you can’t see. Tools like Query Monitor are great for deep debugging, but a simpler, all‑in‑one solution is the free plugin Hungry Resource Monitor. It provides:
- A dashboard of top resource consumers.
- One‑click cleanup of revisions, transients, and orphaned data.
- A list of all cron jobs with orphaned ones highlighted.
- Detection of unused plugins and themes.
- Optional weekly email reports.
Full disclosure: the plugin is built by the author of this article, but it’s free and works locally—no data is sent elsewhere.
Practical steps you can take today
Limit post revisions
Add the following line to wp-config.php:
define('WP_POST_REVISIONS', 5); // Keep only 5 revisions per post
You can also prune old revisions with WP‑CLI or a dedicated cleanup plugin.
Remove unused plugins and themes
Every deactivated plugin still loads on every page request unless you delete it entirely. Removing unused code reduces memory usage and potential security risks.
Audit autoloaded options
WordPress loads all options marked autoload = 'yes' on every request. Large autoloaded entries can significantly slow down the site. Run this query to identify the biggest offenders:
SELECT option_name, LENGTH(option_value) AS size
FROM wp_options
WHERE autoload = 'yes'
ORDER BY size DESC
LIMIT 20;
Consider setting unnecessary options to autoload = 'no' or cleaning them up entirely.
Schedule regular cleanups
Whether you use a plugin or WP‑CLI, set up a routine (e.g., weekly) to:
- Delete old revisions.
- Expire or delete stale transients.
- Remove orphaned postmeta and other unused data.
- Clean up orphaned cron jobs.
Bottom line
WordPress performance isn’t about a single magic fix. It’s about gaining visibility into where resources are consumed and regularly cleaning up the inevitable clutter. Start by installing Hungry Resource Monitor, review the dashboard, and apply the practical steps above. Your site will stop “bleeding” memory and run much smoother.