Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenFragmentationPercent(Gen) sometimes throws a null ref exception #2012

Open
mrsharm opened this issue Mar 21, 2024 · 0 comments
Open

GenFragmentationPercent(Gen) sometimes throws a null ref exception #2012

mrsharm opened this issue Mar 21, 2024 · 0 comments

Comments

@mrsharm
Copy link
Contributor

mrsharm commented Mar 21, 2024

The call to GenSizeAfterMB in the GenFragmentationPercent call is what causes the null ref.

    public double GenFragmentationPercent(Gens gen)
    {
        return GenFragmentationMB(gen) * 100.0 / GenSizeAfterMB(gen);
    }

That GenSizeAfterMB call fails if the HeapStats are somehow null:

    public double GenSizeAfterMB(Gens gen)
    {
        return gen switch
        {
            Gens.GenPinObj => (double)HeapStats.GenerationSize4 / 1000000.0,
            Gens.GenLargeObj => (double)HeapStats.GenerationSize3 / 1000000.0,
            Gens.Gen2 => (double)HeapStats.GenerationSize2 / 1000000.0,
            Gens.Gen1 => (double)HeapStats.GenerationSize1 / 1000000.0,
            Gens.Gen0 => (double)HeapStats.GenerationSize0 / 1000000.0,
            _ => double.NaN,
        };
    }

This should be guarded against.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant