Skip to content

Remove usage of finalizers wherever possible #4229

@peppy

Description

@peppy

While investigating ppy/osu#11800, we have basically identified the root cause to be the presence of objects with finalizers (even if they have been suppressed) existing in the finalizer queue.

Using the following model classes:

public class NonFinalizingThing
{
    public NonFinalizingThing()
    {
    }
}

public class FinalizingThing
{
    public FinalizingThing()
    {
    }

    ~FinalizingThing()
    {
    }
}

Constant allocations without finalizer:

for (int i = 0; i < 100000000; i++)
{
    var thing = new NonFinalizingThing();
}

20210301 194407 (Parallels Desktop app)

With:

for (int i = 0; i < 100000000; i++)
{
    var thing = new FinalizingThing();
    GC.SuppressFinalize(thing);
}

20210301 194500 (Parallels Desktop app)

Note the pause time increasing from 0.1ms to around 7ms.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions