Skip to content

fix: corrected FileLottie.hashCode to prevent cache memory leak#417

Merged
xvrh merged 1 commit into
xvrh:masterfrom
BenjaminDucombs:fix/file-lottie-cache-hashcode-memory-leak
Jun 1, 2026
Merged

fix: corrected FileLottie.hashCode to prevent cache memory leak#417
xvrh merged 1 commit into
xvrh:masterfrom
BenjaminDucombs:fix/file-lottie-cache-hashcode-memory-leak

Conversation

@BenjaminDucombs

Copy link
Copy Markdown
Contributor

From issue #412:

Problem

FileLottie.operator== compared file.path, but hashCode returned
file.hashCode (the identity hash of the io.File object). This violated
the hashCode/== contract: two FileLottie instances pointing to the
same path were considered equal but produced different hash codes.

As a result, sharedLottieCache.putIfAbsent(this, ...) always missed on
a hash lookup, inserting a new cache entry every time the same file was
loaded. Over time this caused the cache to grow without bound, leaking
memory.

Fix

Change hashCode to use file.path.hashCode so it is consistent with
the equality comparison.

// before
int get hashCode => file.hashCode;

// after
int get hashCode => file.path.hashCode;

@xvrh xvrh merged commit 3fc5b1c into xvrh:master Jun 1, 2026
1 of 3 checks passed
@xvrh

xvrh commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution!

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