Skip to content

fix: cleanup _idmap of $ZodRegistry #4837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2025
Merged

Conversation

safareli
Copy link
Contributor

@safareli safareli commented Jul 7, 2025

No description provided.

@safareli
Copy link
Contributor Author

safareli commented Jul 7, 2025

shouldn't _idmap: Map<string, Schema> = new Map(); be WeakMap too? otherwise presense of id in meta results in strong pointer of Schema to be created which means it will not be removed from the _map ever even if there are no strong pointers to Schema from outside of this class thus creating mem leak potential.

@colinhacks
Copy link
Owner

You're correct. Unfortunately registries need to be iterable for z.toJSONSchema() as implemented (this is why CI is failing), and the fact that it's using WeakRef for the schema map is a bit of a vestige of an older implementation. I think I'll be switching to a plain Map and adding a .clear() method. It's not ideal, but honestly I think a true WeakMap implementation would also cause a lot of mysterious issues for people who don't understand how they work. Regardless, merging this fix 👍 Thank you.

@colinhacks colinhacks merged commit 91c9ca6 into colinhacks:main Jul 7, 2025
3 of 4 checks passed
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy