Repository navigation
WinClean v2.3 - Critical Bug Fix
Critical Bug Fix
The Problem
"Space freed" always showed 0 bytes in the final statistics window, regardless of how much disk space was actually cleaned.
Users saw:
╔══════════════════════════════════════════════════════════════════════╗
║ Duration: 00:05:23 ║
║ Space freed: 0 Bytes ← Always zero! ║
╚══════════════════════════════════════════════════════════════════════╝
Root Cause
The code used [System.Threading.Interlocked]::Add([ref]$script:Stats.TotalFreedBytes, $freed) to update the counter.
Problem: In PowerShell, [ref] doesn't work with hashtable elements! It creates a temporary copy of the value instead of a reference to the hashtable slot. Interlocked.Add modified this temporary value, which was then discarded.
# This DOESN'T work in PowerShell:
[System.Threading.Interlocked]::Add([ref]$hashtable.Key, $value)
# The $hashtable.Key remains unchanged!The Fix
Replaced all 6 occurrences with simple += operator:
# Before (broken):
[System.Threading.Interlocked]::Add([ref]$script:Stats.TotalFreedBytes, $freed) | Out-Null
# After (works):
$script:Stats.TotalFreedBytes += $freedThe synchronized hashtable already provides thread-safety for basic operations.
Impact
- Affected versions: 2.0, 2.1, 2.2
- Symptoms: "Space freed: 0 Bytes" in final statistics
- Actual cleanup: Was working correctly, only the counter was broken
Upgrade
Replace your existing WinClean.ps1 with the new version. No configuration changes needed.
Full Changelog: https://github.com/bivlked/WinClean/blob/main/CHANGELOG.md