swift-memory-allocation 0.1.0
Cross-platform memory allocation observability for Swift
The initial release of swift-memory-allocation provides comprehensive memory allocation tracking, leak detection, and profiling capabilities across macOS and Linux platforms.
Features
- Allocation Tracking - Measure memory allocations in code blocks with
AllocationTracker - Leak Detection - Detect memory leaks by tracking net allocations with
LeakDetector - Peak Memory Tracking - Monitor peak memory usage over time with
PeakMemoryTracker - Allocation Profiling - Profile allocations with statistics and histograms using
AllocationProfiler - Cross-Platform - Works on macOS/iOS/watchOS/tvOS and Linux with platform-optimized implementations
- Thread-Safe - All trackers are Sendable and safe for concurrent use
- Zero Dependencies - Pure Swift using only Darwin/Glibc platform primitives (no Foundation)
Requirements
- Swift 6.2+
- macOS 13+, iOS 16+, watchOS 9+, tvOS 16+, or Linux
Installation
Swift Package Manager
Add to your Package.swift:
dependencies: [
.package(url: "https://github.com/coenttb/swift-memory-allocation", from: "0.1.0")
]Then add it to your target:
.target(
name: "YourTarget",
dependencies: [
.product(name: "MemoryAllocation", package: "swift-memory-allocation")
]
)Quick Example
import MemoryAllocation
// Measure allocations
let (result, stats) = AllocationTracker.measure {
let array = Array(repeating: 0, count: 1000)
return array.count
}
print("Allocated \(stats.bytesAllocated) bytes")Documentation
Full documentation and examples available in the README.
Technical Details
- Swift 6.2 with modern upcoming features (
ExistentialAny,MemberImportVisibility,InternalImportsByDefault) - Comprehensive test suite with 88 tests including README verification
- CI/CD with SwiftLint and swift-format
Project Homepage: https://coenttb.com
License: Apache License 2.0