Memory-management fixes
Two pre-existing issues called out during the 0.3.0 review are now resolved. No source changes required for consumers — same behavior for correct call sites; previously-leaked memory is now reclaimed.
Fixes
Connection↔SwiftWebServerretain cycle (#6, PR #8).Connection.serveris now aweakreference, so the staticSwiftWebServer.connectionsdictionary no longer pins the server graph (and itsrouteHandlers/ middleware / closures) through its connections. Masked in CLI / one-shot use, but observable as growing RSS in long-running apps that bring servers up and down.- CFSocket context retain leak in
listen()(#7, PR #9).listen(_:host:completion:)previously usedUnmanaged.passRetained(self)for theCFSocketContextinfopointer with bothretain/releasecallbacksnil, leaking one refcount perlisten()call. Now usespassUnretained(self)with matchingretain/releasecallbacks so the IPv4 and IPv6 sockets each contribute a balanced retain/release pair againstself.
Documentation
- README refresh (PR #10). Brings the README into sync with the actual public API on
main: replaces the outdatedstart()/stop()snippets withlisten(_:host:completion:)/close(), documents the@MainActor/Sendablecontract, adds a loopback-bind subsection, and corrects the platform Requirements (iOS 15 / macOS 12 / Swift 5.10 / Xcode 15.3 for the library; iOS 17 / macOS 14 only for the SwiftUI example app, which uses SwiftData). Reviewed by Claude, Codex, and Copilot.
Tests
46/46 passing, including two new regression tests:
ConnectionRetainCycleTests— constructs aConnectionreferencing a server, drops the user's strong reference, asserts the server deallocates even while theConnectionis alive.testServerDeinitsAfterCloseDoesNotLeak— listens on an ephemeral loopback port, closes, asserts the server deallocates via a weak reference.
Compatibility
- No source changes required.
- No behavior change for correct call sites; previously-leaked memory is now reclaimed.