Skip to content

0.3.1

Latest

Choose a tag to compare

@atom2ueki atom2ueki released this 01 May 16:03
904f2bb

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

  • ConnectionSwiftWebServer retain cycle (#6, PR #8). Connection.server is now a weak reference, so the static SwiftWebServer.connections dictionary no longer pins the server graph (and its routeHandlers / 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 used Unmanaged.passRetained(self) for the CFSocketContext info pointer with both retain / release callbacks nil, leaking one refcount per listen() call. Now uses passUnretained(self) with matching retain / release callbacks so the IPv4 and IPv6 sockets each contribute a balanced retain/release pair against self.

Documentation

  • README refresh (PR #10). Brings the README into sync with the actual public API on main: replaces the outdated start() / stop() snippets with listen(_:host:completion:) / close(), documents the @MainActor / Sendable contract, 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 a Connection referencing a server, drops the user's strong reference, asserts the server deallocates even while the Connection is 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.