Code Analysis
1. Where is the finalizable type implemented?
Both ResourceWrapper and LoggedResource are finalizable types because they define
finalizers using the ~ClassName() syntax.
2. How would I log its destruction?
Destruction is logged inside each finalizer using [Link](). ResourceWrapper
prints 'Finalizer called!' and LoggedResource prints the resource name and updated live
count.
3. Where are objects created, references dropped, and garbage collection forced?
Objects are created with the new keyword in CreateResources() and
CreateResourcesLoop(). References are dropped when the local variables go out of scope at
the end of the method or each loop iteration. Garbage collection is forced in Main() using
[Link]() followed by [Link]().
4. Where is ResourceWrapper?
ResourceWrapper is the first class in the program. It wraps an unmanaged IntPtr handle,
allocates it in the constructor, and releases it in its finalizer.
5. Where is LoggedResource?
LoggedResource is the second class in the program. It logs object creation in its constructor
and object finalization in its finalizer. Instances are created in CreateResources() and
CreateResourcesLoop().
Question Answer
Where is the finalizable type implemented? In ResourceWrapper and LoggedResource,
both containing a finalizer.
How is destruction logged? Using [Link]() inside each
finalizer.
Where are objects created? Using new LoggedResource(...) in
CreateResources() and
CreateResourcesLoop().
Where are references dropped? When local variables go out of scope.
Where is garbage collection forced? In Main() with [Link]() and
[Link]().
Where is ResourceWrapper? First class in the file.
Where is LoggedResource? Second class in the file.