Skip to content

Conversation

@laggykiller
Copy link
Contributor

@laggykiller laggykiller commented Mar 27, 2025

Currently, liq_result_p, liq_image, liq_attr are not cleaned if RuntimeError occurs.

This can potentially cause memory leak, such as in the following example:

import imagequant
from PIL import Image

def smallest_quant(image: Image) -> Image:
    image_quant = None
    for i in range(11, 101, 5):
        try:
            image_quant = imagequant.quantize_pil_image(  # type: ignore
                image,
                dithering_level=1.0,
                max_colors=256,
                min_quality=0,
                max_quality=i,
            )
            return image_quant
        except RuntimeError:
            pass

    return image

This PR cleans up liq_result_p, liq_image, liq_attr before throwing RuntimeError.

@flozz
Copy link
Member

flozz commented Mar 28, 2025

Oops, nice catch! :)

@flozz flozz merged commit 7cd36e4 into wanadev:master Mar 28, 2025
5 checks passed
@flozz
Copy link
Member

flozz commented Mar 28, 2025

Released in v1.1.4, packages build in progress.

Thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants