dotnet / dotnet/dotnet-api-docs

GC.ReRegisterForFinalize(Object) Method – object arg/param is not limited to caller

Open
#7,151 5 comments 0 reactions 0 assignees View on GitHub
area-System.Runtime Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

From [Remarks](https://docs.microsoft.com/en-us/dotnet/api/system.gc.reregisterforfinalize?view=net-5.0#remarks)
> The ReRegisterForFinalize method adds the obj parameter to the list of objects that request finalization before the garbage collector frees the object. The obj parameter must be the caller of this method.

Verifying example one can gather no error on `GC.ReRegisterForFinalize (new object());` call.
```csharp
class Program
{
static async Task Main ( string[] args )
{
Test test;
foreach(var i in Enumerable.Range(0, 2))
test = new Test ();

test = null;
GC.Collect ();

await Task.Delay (1_000);
}

class Test
{
~Test ()
{
Console.WriteLine ("AAAA");
GC.ReRegisterForFinalize (this);
GC.ReRegisterForFinalize (new object());
}
}
}
```

### Project
[GcReRegisterForFinalize.zip](https://github.com/dotnet/docs/files/7148204/GcReRegisterForFinalize.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.