fix: Fix headless gui and clock keeping references to emulator and making tests very memory hungry. Added a test to verify this doesnt happen anymore.#2234
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses memory retention issues in headless/UI-related components and the emulated clock wiring that could keep emulator instances rooted across test runs, leading to high memory usage. It also updates the test suite to rely on xUnit v3’s built-in skip mechanisms and adds an assembly-wide leak guard to prevent regressions.
Changes:
- Prevent
HeadlessGuiinstances from being rooted via process-lifetime static events by unsubscribing on dispose. - Avoid
Spice86DependencyInjectionbeing captured by pause/resume event closures by capturing the clock via a local variable instead of the DI instance. - Add a suite-wide machine leak tracker/guard and update tests to use
Assert.SkipUnless+[Fact](removingXunit.SkippableFactusage).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Spice86.Tests/Video/VgaRenderer256ColorTestsBase.cs | Switches from SkippableFact to xUnit v3 runtime skipping via Assert.SkipUnless. |
| tests/Spice86.Tests/Video/RendererTestsBase.cs | Same: replaces Skip.IfNot/[SkippableFact] with xUnit v3 equivalents. |
| tests/Spice86.Tests/Spice86Creator.cs | Tracks created Machine instances so the assembly-wide leak guard can validate collectability. |
| tests/Spice86.Tests/Spice86.Tests.csproj | Removes Xunit.SkippableFact and uses xunit.v3 (enabling built-in skip + fixtures). |
| tests/Spice86.Tests/MachineLeakTracker.cs | Adds weak-reference tracking of created Machine instances for leak detection. |
| tests/Spice86.Tests/MachineLeakGuard.cs | Adds an assembly fixture that fails the run if tracked machines survive post-dispose GC. |
| tests/Spice86.Tests/Http/HttpApiGeneratedClientIntegrationTests.cs | Moves to IClassFixture and seeds memory values used by assertions. |
| src/Spice86/ViewModels/Services/HeadlessGui.cs | Unsubscribes from static events on dispose to avoid instance rooting/leaks. |
| src/Spice86/Spice86DependencyInjection.cs | Prevents pause handler event closures from capturing the DI instance (reducing retention risk). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
maximilien-noal
approved these changes
Jun 22, 2026
4ea0bfd to
40d2d8c
Compare
|
|
||
| public static int CountSurvivingAfterCollection() { | ||
| for (int i = 0; i < 3; i++) { | ||
| GC.Collect(); |
| for (int i = 0; i < 3; i++) { | ||
| GC.Collect(); | ||
| GC.WaitForPendingFinalizers(); | ||
| GC.Collect(); |
…king tests very memory hungry. Added a test to verify this doesnt happen anymore.
40d2d8c to
24cd9c1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.