I have developed a wordpress plugin that reads large custom xml files and imports the information as custom post types and a lot of post meta information. So I am calling a lot of database transactions. The plugin runs for several minutes within one POST’ed process and then aborts with out of memory (250 MB).
Tracking the problem down to a minimum I have a minimal example that shows the problem. This example is leaking about 18 kbyte and this is summing heavily up during runtime of the plugin. The query checks if a post with a given title exists (
echo "<p>memory: " . memory_get_usage() . "</p>"; global $wpdb; $poststable = $wpdb->prefix."posts"; $items = $wpdb->get_results("SELECT ID FROM $poststable WHERE post_title='$title'"); unset($items); $wpdb->flush(); echo "<p>memory: " . memory_get_usage() . "</p>";
The output is
so the difference is about 18 kbyte. Where are those bytes? Although this is a small amount of memory it is summing up to several hundred megabytes.
@IlmarsL: thanks! I really did not think of that. I had the plugin Query Monitor enabled and this was the problem… Turning Query Monitor off solved the problem and memory did no more longer increase.