SShortSingh.
Back to feed

Two Silent Python Memory Leaks That Slip Past Code Review and How to Catch Them

0
·5 views

Long-running Python services such as FastAPI servers and Celery workers still run out of memory in production, despite automatic reference counting and cyclic garbage collection. Most of these leaks stem from unintended strong references that keep short-lived objects alive indefinitely. Such leaks often escape unit tests, since a single test creates one object and then exits. The author demonstrates two common cases in a Python 3.12 lab: applying functools.lru_cache to an instance method, which pins each instance in the cache, and an event bus that retains subscribers that never unsubscribed. Fixes include moving the cache to a module-level function keyed on primitive values and using weakref.WeakMethod, with pytest memory-growth assertions to guard against regressions.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

AWS Lambda Adds Customer-Managed Runtimes for Updates Without Function Redeploys

AWS has made Lambda customer-managed runtimes generally available in all commercial Regions since November 18, 2026. Platform teams package a runtime as an OCI image in Amazon ECR, and functions receive updates by moving a runtime alias without redeployment. The feature supports only Event Functions, not Web Functions, and excludes SnapStart and Lambda@Edge. There is no added Lambda charge, though customers pay standard ECR storage fees for the images. Responsibility for patching shifts to the customer, and publishers may run code inside consuming functions.

0
ProgrammingDEV Community ·

Aurora DSQL adds intercontinental multi-Region clusters, PL/pgSQL support and higher write throughput

Amazon Aurora DSQL received three updates announced on November 19, 2026, covering multi-Region clusters spanning continents, PL/pgSQL stored functions and procedures, and storage-layer improvements. Peer Regions can now sit on different continents, with US East (N. Virginia) and Europe (Ireland) given as an example. The database also supports stored functions and procedures, though exception blocks and explicit cursors are not available and return a feature-not-supported error. Storage upgrades are said to raise write throughput by up to 50% for many transactional workloads, at no stated extra cost. Enablement steps and general availability status were not specified in the announcement.

0
ProgrammingDEV Community ·

Dynamic LLM Routing Aims to Cut AI Costs and Improve Performance

Developers integrating multiple large language models often face rising costs, inconsistent performance, and vendor lock-in that complicate maintenance. The article argues that hardcoding individual model calls into applications creates this sprawl and drains both budgets and engineering time. It proposes an intermediary routing layer that analyzes each request's task type and predefined rules, such as cost and performance, to select the most suitable model. This design decouples applications from specific providers, allowing new models to be added or swapped without changing core code. The piece outlines a typical architecture built around a central router, routing logic, and provider-specific adapters.

0
ProgrammingDEV Community ·

Gumroad's fixed per-sale fee cuts small digital product prices hardest

A creator explains that on Gumroad a $19 digital product nets about $15.75 for a direct sale in November 2026, because the fee combines 12.9% with a fixed $0.80. Because the fixed portion weighs heavily on low prices, a $5 product loses nearly 30% of its value, while a $99 sale loses about 13.7%. The writer suggests bundling products or setting a minimum price around $9 to offset the cost. They also note that Discover sales take a flat 30%, making them worse per unit than direct sales above roughly $4.70, but argue this is a marketing cost if it brings buyers otherwise unreachable.