Is there any way to check what instances classes are collected by GC and what are not? The one option i found is by checking class by Test as described here:
How can I write a unit test to determine whether an object can be garbage collected?
Is there any way to check what instances classes are collected by GC and what are not? The one option i found is by checking class by Test as described here:
How can I write a unit test to determine whether an object can be garbage collected?
Is there any way to check what classes are collected by GC and what are not?
No, because to check on an object you'd still need a reference to it and that would prevent its collection.
You can build an administration with WeakReferences but that would be awkward and costly. Certainly not feasible for all objects.
More important, you shouldn't be needing this. If you think you do, analyze that thought train.
create a ReferenceTester
class that will hold A Dictionary
of week references
Dictionary use them to test if class is there.
then call GC.Collect().
then check ReferenceTester
again if class is still there.
You can also tell when an object has been Garbage Collected with the finalizer is called. This is not 100% guaranteed as you still call GC.SupressFinalize() on classes that will prevent the collection.