Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade VB6 Container Class to VB.NET

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?

like image 892
Adam Boyce Avatar asked Mar 24 '23 15:03

Adam Boyce


1 Answers

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.

like image 72
Federico Berasategui Avatar answered Apr 01 '23 12:04

Federico Berasategui