Title: register_vector leaks dumper classes on every call · Issue #168 · pgvector/pgvector-python · GitHub
Open Graph Title: register_vector leaks dumper classes on every call · Issue #168 · pgvector/pgvector-python
X Title: register_vector leaks dumper classes on every call · Issue #168 · pgvector/pgvector-python
Description: Hi! Investigating a memory leak in our API, we found out that register_vector (and register_vector_async) creates 8 classes on every call that are never garbage collected if psycopg's C extension is in use, even after the connection is c...
Open Graph Description: Hi! Investigating a memory leak in our API, we found out that register_vector (and register_vector_async) creates 8 classes on every call that are never garbage collected if psycopg's C extension i...
X Description: Hi! Investigating a memory leak in our API, we found out that register_vector (and register_vector_async) creates 8 classes on every call that are never garbage collected if psycopg's C extensi...
Opengraph URL: https://github.com/pgvector/pgvector-python/issues/168
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"register_vector leaks dumper classes on every call","articleBody":"Hi!\nInvestigating a memory leak in our API, we found out that `register_vector` (and `register_vector_async`) creates 8 classes on every call that are never garbage collected if psycopg's C extension is in use, even after the connection is closed.\n\nThis is because these classes are stored by psycopg in a dict shared by the whole python process, and never cleared. \n\npgvector python 0.4.2 (but the code has not been updated on master) and psycopg 3.3.2\n\nTo reproduce:\n```python\nimport gc\nfrom types import SimpleNamespace\n\nimport psycopg\nfrom pgvector.psycopg.vector import (\n VectorBinaryDumper,\n VectorDumper,\n register_vector_info,\n)\nfrom psycopg.adapt import AdaptersMap\nfrom psycopg.types import TypeInfo\n\n\ndef count() -> int:\n gc.collect()\n return sum(\n 1\n for base in (VectorDumper, VectorBinaryDumper)\n for c in base.__subclasses__()\n if c.__name__ == \"\"\n )\n\n\nprint(psycopg.__version__, psycopg.pq.__impl__)\nbefore = count()\nfor _ in range(1000):\n ctx = SimpleNamespace(adapters=AdaptersMap(psycopg.adapters))\n register_vector_info(ctx, TypeInfo(\"vector\", 16385, 16386))\n del ctx\nprint(\"leaked dumper classes:\", count() - before) # expected 0, prints 2000\n```\n\n\nCaching these classes as done by psycopg could fix the issue : https://github.com/psycopg/psycopg/blob/99356800e90aa0e7b604f652d714ef0f33422b47/psycopg/psycopg/types/hstore.py#L225","author":{"url":"https://github.com/lsviennot","@type":"Person","name":"lsviennot"},"datePublished":"2026-10-21T16:03:26Z","url":"https://github.com/pgvector/pgvector-python/issues/168"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:eff30475-1cdf-4d7b-a699-2a9e99aaae3a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8B76:202219:659D6D:8D4F14:6AFEAAF9 |
| html-safe-nonce | 0e23b7a7c6ba257b80ee19a69afdff1b235939b7d84db888ae9134a874bbc09d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Qjc2OjIwMjIxOTo2NTlENkQ6OEQ0RjE0OjZBRkVBQUY5IiwidmlzaXRvcl9pZCI6Ijc1Mjg0NjA5NDQ0NDQxNDAyODEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 463582a26cb688b65567f97029df076fe1c87125c3cf88876802a9d841454abb |
| hovercard-subject-tag | issue:5964050188 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pgvector/pgvector-python/168/issue_layout |
| twitter:image | https://opengraph.githubassets.com/821b79035577e82007db923ebec84ad940be4f6f50f846009dd999da19aefc49/pgvector/pgvector-python/issues/168 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/821b79035577e82007db923ebec84ad940be4f6f50f846009dd999da19aefc49/pgvector/pgvector-python/issues/168 |
| og:image:alt | Hi! Investigating a memory leak in our API, we found out that register_vector (and register_vector_async) creates 8 classes on every call that are never garbage collected if psycopg's C extension i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lsviennot |
| hostname | github.com |
| expected-hostname | github.com |
| None | 95b2753c978240785d6cca00783c00a371b2d7d9879bb32e305170a1b19bd28e |
| turbo-cache-control | no-preview |
| go-import | github.com/pgvector/pgvector-python git https://github.com/pgvector/pgvector-python.git |
| octolytics-dimension-user_id | 98363230 |
| octolytics-dimension-user_login | pgvector |
| octolytics-dimension-repository_id | 376300726 |
| octolytics-dimension-repository_nwo | pgvector/pgvector-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 376300726 |
| octolytics-dimension-repository_network_root_nwo | pgvector/pgvector-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3f25273206cd841171bca0002261ae4c9757d934 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width