The problem
File handles, database connections and sockets that are never closed stay open until something else cleans up, holding memory and server capacity and eventually forcing restarts.
The fix you can use today
- Use with in Python, try-with-resources in Java, using in C#, defer in Go.
- Reuse connections through a pool instead of opening one per request.
- Watch open-connection counts in production.
Tools that help
- GreenCode Constitution skill (GreenCode researchers): open-source energy principles and a catalogue of 37 energy anti-patterns that an AI coding agent can follow to find and fix waste like this
- SonarQube: static analysis for code smells, bugs and security issues, with quality gates in CI
How GreenCode helps
GreenCode helps tackle this by scoring a codebase for quality, security and green software patterns in one pass, so a leak like this comes out as a ranked defect alongside the bugs and security findings. More on this.
Tags
#memory#databases#python#java
Sources
All GreenCode Tech Tips