PHP Fatal error: Allowed memory size of 201326592 bytes (192 megabytes) exhausted (tried to allocate 8192 bytes) in sites/all/modules/imageapi/imageapi_imagemagick.module on line 206

PHP Stack trace: 
PHP   1. {main}() /root/drush/drush.php:0
PHP   2. drush_main() /root/drush/drush.php:42
PHP   3. drush_dispatch() /root/drush/drush.php:102
PHP   4. call_user_func_array() /root/drush/includes/
PHP   5. imagecache_drush_preset_build() /root/drush/includes/
PHP   6. imagecache_generate_image() sites/all/modules/imagecache/
PHP   7. imagecache_build_derivative() sites/all/modules/imagecache/imagecache.module:1250
PHP   8. imageapi_image_close() sites/all/modules/imagecache/imagecache.module:609
PHP   9. imageapi_toolkit_invoke() sites/all/modules/imageapi/imageapi.module:404
PHP  10. call_user_func_array() sites/all/modules/imageapi/imageapi.module:166
PHP  11. imageapi_imagemagick_image_close() sites/all/modules/imageapi/imageapi.module:0
PHP  12. _imageapi_imagemagick_convert() sites/all/modules/imageapi/imageapi_imagemagick.module:105
PHP  13. _imageapi_imagemagick_convert_exec()sites/all/modules/imageapi/imageapi_imagemagick.module:154
PHP  14. fgets() sites/all/modules/imageapi/imageapi_imagemagick.module:206

Happened after generating close to 1 million images via drush


drewish’s picture

I don't think that's necessarily ImageAPI's fault. There's lots of code that gets executed that could be leaking but since ImageAPI makes big requests for memory it'll be the one left holding the bag when it finally runs out. I think that's exactly the reason Drush monitors memory usage and starts new processes periodically to work around this.

mikeytown2’s picture

Drush was running the imagecache generation script for around 6 hours before it finally gave up the ghost; so it's a slow leak, wherever it is. Luckily I just needed to restart it and it kept going where it was last.

pribeh’s picture

I'm experiencing this as well. What did you do to resolve this mikeytown2?

mikeytown2’s picture

This was caused from running the drush generate imagecache preset. I just ran it again because the drush script only generates files that do not exist. This leak turned fatal after several hours of it running the same script. Are these the same conditions that caused this error for you or was it something else?

pribeh’s picture

Hi mikeytown2, no it isn't under the same conditions. I wrote the comment in a rush and also because it's the only one similar enough to what I'm experiencing. Every so often I'll run into a node (with several cck imagefields) that when attempting to edit the node I will get a very similar report (except I'm using gd instead of imagemagick).

mikeytown2’s picture

sounds like GD is using up your php memory when loading a large image. This is to be expected and in your case up your php memory limit. drewish's comment in #1 makes sense for you. In my case this is the same code running again and again for several hours, slowly eating up ram for no good reason. It may not be ImageAPI that is leaking, but it does have something to do with the image generation logic. It only affects me rarely and and it has an easy solution (run the drush script again), so I haven't debugged this to find the exact cause.

Dane Powell’s picture

This is still an issue with image in Drupal core. With every round of image generation by drush image-generate, I see memory usage tick up by about 30KB, until it eventually errors out. When you're dealing with hundreds of thousands of images, that's a pain. I haven't been able to narrow down where the memory leak is.