0% found this document useful (0 votes)
4 views1 page

6) FinalizerLab Code Analysis

The document discusses the implementation of finalizable types ResourceWrapper and LoggedResource, detailing their finalizers and destruction logging methods. It explains where objects are created, how references are dropped, and where garbage collection is forced in the program. Additionally, it specifies the positions of ResourceWrapper and LoggedResource within the code structure.

Uploaded by

johnsonshanton4
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

6) FinalizerLab Code Analysis

The document discusses the implementation of finalizable types ResourceWrapper and LoggedResource, detailing their finalizers and destruction logging methods. It explains where objects are created, how references are dropped, and where garbage collection is forced in the program. Additionally, it specifies the positions of ResourceWrapper and LoggedResource within the code structure.

Uploaded by

johnsonshanton4
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like