Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can't remove Visual Basic 2008 DLL From memory

Posted on 2011-09-06
5
Medium Priority
?
204 Views
Last Modified: 2012-05-12
I created a Visual Basic DLL using Visual Studio 2008. I have referenced this DLL in a windows form. After I use it I want to dispoase of it. I set it to nothing. But when I use it again, it retained its memory values. This tells me it was not actually removed from memory.

Here is my code:
 
dim objNewCustomer as new WebToMacDll.clsMain
With objNewCustomer
      .RequestNameString = "NEWCUSTOMER"
      .TableIDNoLong = 5
      .ProcessThisRequest()
      StatusMessageString = .StatusMessaageString
End With
objNewCustomer = nothing
'

Open in new window


When I call this code a second time, all the variables have retained their previous values. If the objNewCustomer = Nothing would have removed it from memory, I believe the variable would have all been empty.

How do I remove the DLL from memory after calling it?

Thanks,
pat
0
Comment
Question by:mpdillon
  • 3
  • 2
5 Comments
 

Author Comment

by:mpdillon
ID: 36493029
I found this msdn article. MSDN IDisposeable

I thought it would implement a Dispose method. The Class code to my DLL is included below.

 
Option Explicit On
Imports System
Imports System.ComponentModel

<ComClass(clsMain.ClassId, clsMain.InterfaceId, clsMain.EventsId)> _
Public Class clsMain

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class 
    ' and its COM interfaces. If you change them, existing 
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "4e2a0632-6659-4cd2-a059-448f7b53b509"
    Public Const InterfaceId As String = "2a8fe9ab-1918-4a65-aca4-cc8502d9a415"
    Public Const EventsId As String = "94481a6c-f43d-4f0f-a82f-18ce7d33c887"
#End Region

    ' A creatable COM class must have a Public Sub New() 
    ' with no parameters, otherwise, the class will not be 
    ' registered in the COM registry and cannot be created 
    ' via CreateObject.
    Public Sub New()
        MyBase.New()
    End Sub
    '
    ' A class that implements IDisposable.
    ' By implementing IDisposable, you are announcing that 
    ' instances of this type allocate scarce resources.
    Public Class MyResource
        Implements IDisposable
        ' Pointer to an external unmanaged resource.
        Private handle As IntPtr
        ' Other managed resource this class uses.
        Private component As Component
        ' Track whether Dispose has been called.
        Private disposed As Boolean = False

        ' The class constructor.
        Public Sub New(ByVal handle As IntPtr)
            Me.handle = handle
        End Sub

        ' Implement IDisposable.
        ' Do not make this method virtual.
        ' A derived class should not be able to override this method.
        Public Overloads Sub Dispose() Implements IDisposable.Dispose
            Dispose(True)
            ' This object will be cleaned up by the Dispose method.
            ' Therefore, you should call GC.SupressFinalize to
            ' take this object off the finalization queue 
            ' and prevent finalization code for this object
            ' from executing a second time.
            GC.SuppressFinalize(Me)
        End Sub

        ' Dispose(bool disposing) executes in two distinct scenarios.
        ' If disposing equals true, the method has been called directly
        ' or indirectly by a user's code. Managed and unmanaged resources
        ' can be disposed.
        ' If disposing equals false, the method has been called by the 
        ' runtime from inside the finalizer and you should not reference 
        ' other objects. Only unmanaged resources can be disposed.
        Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
            ' Check to see if Dispose has already been called.
            If Not Me.disposed Then
                ' If disposing equals true, dispose all managed 
                ' and unmanaged resources.
                If disposing Then
                    ' Dispose managed resources.
                    component.Dispose()
                End If

                ' Call the appropriate methods to clean up 
                ' unmanaged resources here.
                ' If disposing is false, 
                ' only the following code is executed.
                CloseHandle(handle)
                handle = IntPtr.Zero

                ' Note disposing has been done.
                disposed = True

            End If
        End Sub

        ' Use interop to call the method necessary  
        ' to clean up the unmanaged resource.
        <System.Runtime.InteropServices.DllImport("Kernel32")> _
        Private Shared Function CloseHandle(ByVal handle As IntPtr) As [Boolean]
        End Function

        ' This finalizer will run only if the Dispose method 
        ' does not get called.
        ' It gives your base class the opportunity to finalize.
        ' Do not provide finalize methods in types derived from this class.
        Protected Overrides Sub Finalize()
            ' Do not re-create Dispose clean-up code here.
            ' Calling Dispose(false) is optimal in terms of
            ' readability and maintainability.
            Dispose(False)
            MyBase.Finalize()
        End Sub
    End Class


    '
    Public Property DebugBoolean() As Boolean
        Get
            Return PublicVariables.DebugBooleanP
        End Get
        Set(ByVal Value As Boolean)
            PublicVariables.DebugBooleanP = Value
        End Set
    End Property

    Public Property OrdNoString() As String
        Get
            Return PublicVariables.OrdNoStringP
        End Get
        Set(ByVal Value As String)
            PublicVariables.OrdNoStringP = Value
        End Set
    End Property
    Public Property InvNoString() As String
        Get
            Return PublicVariables.InvNoStringP
        End Get
        Set(ByVal Value As String)
            PublicVariables.InvNoStringP = Value
        End Set
    End Property
    Public Property MacCusNoString() As String
        Get
            Return PublicVariables.MacCusNoStringP
        End Get
        Set(ByVal Value As String)
            PublicVariables.MacCusNoStringP = Value
        End Set
    End Property
    Public Property MacCusAltAdrCdString() As String
        Get
            Return PublicVariables.MacCusAltAdrCdStringP
        End Get
        Set(ByVal Value As String)
            PublicVariables.MacCusAltAdrCdStringP = Value
        End Set
    End Property
    Public Property StatusMessaageString() As String
        Get
            Return PublicVariables.StatusMessaageStringP
        End Get
        Set(ByVal Value As String)
            PublicVariables.StatusMessaageStringP = Value
        End Set
    End Property
    Public Property StatusMessaageDescString() As String
        Get
            Return PublicVariables.StatusMessaageStringP
        End Get
        Set(ByVal Value As String)
            PublicVariables.StatusMessaageStringP = Value
        End Set
    End Property

    Public Property WSWebLogOnMacCusNo_IDNoLong() As Long
        'This is WSWebLogonMacCusNo.IDNo
        Get
            Return PublicVariables.WSWebLogOnMacCusNo_IDNoLongP
        End Get
        Set(ByVal Value As Long)
            PublicVariables.WSWebLogOnMacCusNo_IDNoLongP = Value
        End Set
    End Property
    '

    Public Property WSWebLogOn_IDNoLong() As Long
        'This is WSWebLogonMacCusNo.IDNo
        Get
            Return PublicVariables.WSWebLogOn_IDNoLongP
        End Get
        Set(ByVal Value As Long)
            PublicVariables.WSWebLogOn_IDNoLongP = Value
        End Set
    End Property
    Public Property WSWebMacAltAddr_IDNoLong() As Long
        'This is WSWebLogonMacCusNo.IDNo
        Get
            Return PublicVariables.WSWebMacAltAddr_IDNoP
        End Get
        Set(ByVal Value As Long)
            PublicVariables.WSWebMacAltAddr_IDNoP = Value
        End Set
    End Property
    Public Property RequestNameString() As String
        Get
            Return PublicVariables.RequestNameStringP
        End Get
        Set(ByVal Value As String)
            PublicVariables.RequestNameStringP = Value
        End Set
    End Property
    Public Property TableIDNoLong() As Long
        Get
            Return PublicVariables.TableIDNoLongP
        End Get
        Set(ByVal Value As Long)
            PublicVariables.TableIDNoLongP = Value
        End Set
    End Property
    Public Sub ProcessThisRequest()
        PublicVariables.CancelBooleanP = False
        PublicVariables.StatusMessaageDescStringP = ""
        PublicVariables.ParmStringP = ""
        PublicVariables.StatusMessaageDescStringP = ""
        PublicVariables.StatusMessaageStringP = ""
        modMain.BeginProcessingThisRequest()
        PublicVariables.CancelBooleanP = False

    End Sub
End Class

Open in new window


I aplogize for the length. I included everything rather than leave something out.

In my calling program, I can see with Intelisense the MyResource class. But I see the Dispose method.

So I am still stuck.
0
 

Author Comment

by:mpdillon
ID: 36493033
Correction.

"But I see the Dispose method"

should read

But I CANNOT see the Dispose method
0
 
LVL 15

Accepted Solution

by:
Minh Võ Công earned 2000 total points
ID: 36493063
0
 

Author Comment

by:mpdillon
ID: 36493230
minhvc,
Thanks for the articles. The first two seem to have some relevance. But why did you post the third link to a music site?

LIke the poster in the second article, I am new to this. So please go slow. It looks like the solution would be to create an AppDomain for the DLL. Is that correct? Since I created the DLL in Visual Studio 2008 (VB) it is managed code correct?

If I created an AppDomain in my Visual Studio testing program, I would be able to add and remove the DLL from memory when ever I wanted. However my Testing program is just that, a TESTING program. The DLL is used by a PHP web server.

I guess I should rephrase the question. What changes do I need to make to my Visual Studio DLL so that it can be called and later removed by a PHP program? I am assuming they do not have access to the AppDomain functionality.

This was fairly simple to do in VB 6. It was handled with Instancing. It can't be this complicated in Visual Studio. I feel I must be missing something very basic (no pun intended).
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question