dotnet / dotnet/dotnet-api-docs
GC.ReRegisterForFinalize(Object) Method – object arg/param is not limited to caller
- 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
Assessment
This issue has not been assessed yet.