Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Cleanup before throwing RuntimeError#26

Merged
flozz merged 1 commit into
wanadev:masterfrom
laggykiller:master
Mar 28, 2025
Merged

Cleanup before throwing RuntimeError#26
flozz merged 1 commit into
wanadev:masterfrom
laggykiller:master

Conversation

@laggykiller

@laggykiller laggykiller commented Mar 27, 2025

Copy link
Copy Markdown
Contributor

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

flozz commented Mar 28, 2025

Copy link
Copy Markdown
Member

Oops, nice catch! :)

@flozz flozz merged commit 7cd36e4 into wanadev:master Mar 28, 2025
@flozz

flozz commented Mar 28, 2025

Copy link
Copy Markdown
Member

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