Putting Dispose and Finalize Together

Implementing Dispose and Finalize cannot necessarily be required. It depends only on what kind of work your objects perform. Table 8.1 summarizes what and when you should implement.

Table 8.1 Implementing Destructors

image

You already have examples about Finalize and Dispose, so here you get an example of their combination. Before you see the code, you have to know that you will see invocations to Win32 unmanaged APIs that you do not need in real applications but these kinds of functions are useful to understand to know how to release unmanaged resources. Now take a look at Listing 8.2.

Listing 8.2 Implementing ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.