Skip to content

Conversation

maxkatz6
Copy link
Member

@maxkatz6 maxkatz6 commented Sep 5, 2025

What does the pull request do?

For each test executed we recreate application services, isolating them. Including font manager. But we do not dispose these, keeping all the native memory alive.

There are really two options to solve it:

  1. Do explicit dispose (done in this PR). I went this direction, because we already did it for UnitTestApplication exactly the same way.
  2. Make sure each skia object has a finalizer, and somehow break managed holds native, native holds managed reference loop in GlyphTypefaceImpl.Face GetTable delegate.

While #2 sounds reasonable to do, FontManager is practically a singleton in normal (non-unit test) applications, and won't do much there. And we still have to properly dispose AvaloniaLocator services after we don't use them.

Checklist

I hope LeakTests won't be flaky one. But also can't use dotMemory extensions properly there, as FontManager is allocated and destroyed outside of the test method itself.

@maxkatz6 maxkatz6 added bug area-headless customer-priority Issue reported by a customer with a support agreement. backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Sep 5, 2025
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0058744-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 self-assigned this Sep 5, 2025
@MrJul MrJul added this pull request to the merge queue Sep 5, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 5, 2025
@maxkatz6 maxkatz6 added this pull request to the merge queue Sep 6, 2025
Merged via the queue into master with commit 56dd94c Sep 6, 2025
12 checks passed
@maxkatz6 maxkatz6 deleted the headless-font-manager-leak branch September 6, 2025 01:40
maxkatz6 added a commit that referenced this pull request Sep 6, 2025
* Dispose font manager after headless session

* Add xunit/nunit LeakTests
@maxkatz6 maxkatz6 added backported-11.3.x and removed backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Sep 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-headless backported-11.3.x bug customer-priority Issue reported by a customer with a support agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants