pyvips: Memory leak when saving pyramid files

When I open a TIFF image using access='sequential' and then save it using compression='jpeg' memory is not released.

Minimal example to reproduce the issue (run passing a large image file path as first parameter:


#!/usr/bin/env python3

import sys

import pyvips

fpath = sys.argv[1]

i = 1
while True:
    print('Iteration {}'.format(i))
    with open(fpath, 'rb') as fh:
        img = pyvips.Image.new_from_buffer(fh.read(), '', access='sequential')
        img.tiffsave('/tmp/flush.tif', compression='jpeg', Q=90)
    i += 1

You can observe memory constantly increasing until eventually the program crashes.

Note that if I don’t use sequential access, or JPEG compression, the memory is flushed as normal.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 52 (25 by maintainers)

Most upvoted comments

@workergnome track this

It can run slower, depending on your code, but you’ll get the same result in the end.

libvips caches the last 1000 or so operations you perform, and will reuse results when it can. This gets you things like common-subexpression removal, and reuse of open images between threads.

pyvips.cache_set_max(0)

What are the implications of disabling the cache (I assume that is what that does) if I want to try it as a temporary workaround?