ropensci/magick

ImageMagick cache is exhausted before gc is triggered

DarwinAwardWinner opened this issue · 1 comments

I have a script in which I'm running magick::image_read on a large number of images in sequence and then immediately discarding the result (the objective is just to verify that it's a valid image that can be read by magick). However, even though each result is discarded, I'm still getting "cache resources exhausted" after a while. I determined that running gc() every 100 or so images seems to prevent this error, so my assumption is that ImageMagick's cache is filling up with images that are no longer referenced but have not yet been garbage collected. Obviously, manually triggering gc every N iterations is a workaround, not a true fix. Is there any way to fix this a bit more elegantly? For example, could image_read check for this error and then trigger gc and try one more time before throwing the error for real?

I also had this problem with large pixel images in a loop and had to call gc manually myself