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 ($title)

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'");
echo "<p>memory: " . memory_get_usage() . "</p>";

The output is memory: 80777008 memory: 80795376 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.

Thanks! Chris

  • Try it with $wpdb->get_var And difference? – shanebp Jan 22 '15 at 22:56
  • unfortunately same result and exactly same amount of memory leaking – Chris Jan 23 '15 at 5:46
  • 1
    I tried running your code, what I got is: memory before: 13393888 memory after: 13392888. Do you have any plug-ins that could be interfering with $wpdb ? Also you could try checking memory usage before flush() and before/after get_results() to narrow down the problem. – IlmarsL Jan 23 '15 at 12:44

@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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.