Okay, so I'm upgrading a VB6 app to VB.NET and I'm unsure of how to modernize the class_terminate component of a container class I'm building:
Private Sub class_terminate()
If Not (colUserMappings Is Nothing) Then
Set colUserMappings = Nothing
End If
End Sub
The issue is that the .NET equivalent of this .Finalize
leaves open some potential runtime errors, because setting a container's final reference to nothing doesn't necessarily destroy the container, as .NET languages have non-deterministic finalization.
That being the case, how would I modernize the collections class in such a way that calling its terminate or finalize function would actually result in the destruction of the container at the end? Is there a good workaround for this?
I would not care too much about this. .Net is a managed, garbage-collected environment. I'm pretty sure the CLR will take care of collecting these objects for you when they're no longer needed.
As a general rule, you should only worry about these kind of things when you're getting a hold of unmanaged resources (such as files, DB Connections, COM objects, etc.). In that case, you may want to implement IDisposable
and properly release all your objects / resources in the Dispose()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With