In Visual Basic, when you create a class reference using the
statement with the
keyword, it is equivalent to a handle to a managed object, similar to C++ handles. The reference can be relocated in memory due to garbage collection and other memory management processes.
is a variable that holds an instance of your
keyword indicates that you want to create a new instance of the class. In this case, memory is allocated for the object, and the reference is stored in the
is declared as a reference to an instance of your
class. It does not hold an actual instance, it's just a reference that can be assigned to point to an instance later on.
would behave the same. They are references to managed objects, and the garbage collector will take care of relocating them as needed.
C++ pointers are closer to raw memory addresses, and they can be used to point to both managed and unmanaged memory, but also require manual memory management and are not automatically relocated like managed references in VB.
As a small example, you can use:
Public Class MyClass
Public Sub New()
Console.WriteLine("MyClass instance was created.")
Dim myclassallocation As New MyClass
Dim myclassreference As MyClass
myclassreference = myclassallocation
myclassreference = Nothing