Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Circular Reference Impact on GC Performance [duplicate]

Possible Duplicate:
Garbage collector and circular reference

Is there any impact on GC performance if objects have a circular reference but are otherwise unattached to any root, and thus ripe for GC?

Would there be any benefit in having a weak ref in one direction?

like image 872
DanH Avatar asked Dec 27 '22 00:12

DanH


2 Answers

Is there any impact on GC performance if objects have a circular reference

No. The sweep process stops when it encounters an instance already visited. There is no diff with non-circular structures.

but are otherwise unattached to any root, and thus ripe for GC?

In that case they will not be visited at all, making it totally irrelevant how many cross links there are.

like image 145
Henk Holterman Avatar answered Feb 01 '23 14:02

Henk Holterman


If the objects can't be reached from the root, they will not be traversed, so a circular reference won't be an issue.

like image 45
Kendall Frey Avatar answered Feb 01 '23 12:02

Kendall Frey