Solved

Releasing of Class Objects??

Posted on 1998-08-05
5
175 Views
Last Modified: 2013-11-23
Hi there,

I've been writing an application that uses class objects and understand that when releasing the object I need to set the variable reference to nothing i.e.

           Set objMyObject = Nothing

However, within the class itself I have several property get statements that return a reference to the object and therefore use the set statement thus:

Public Property Get WinsockControl() As Object
 
      Set WinsockControl = ctlWinsock

End Property

The above example obviously creates a reference to the object - where do I release it??  At the moment my program appears to crash all over the place and I suspect that it may be because objects aren't been released correctly.

Thanks

Pete
0
Comment
Question by:peterwest
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
Jagar earned 100 total points
ID: 1467907
Use the terminate Event of the class and set the object reference to nothing
0
 
LVL 2

Expert Comment

by:Jagar
ID: 1467908
You posted this question twice delete the other one before someone answer it.
0
 
LVL 2

Author Comment

by:peterwest
ID: 1467909
Hi again,

Thanks for telling me about posting the question twice.  Before I grade your answer i'd just like to confirm the following.

Where I have the code:

Public Property Get WinsockControl() As Object
 
      Set WinsockControl = ctlWinsock

End Property


I don't need to do the following:

      Set WinsockControl = Nothing

but I should put the following in the Class_Terminate event:

      Set ctlWinsock = Nothing

Is that correct?

Thanks again,

Pete

0
 
LVL 2

Expert Comment

by:Jagar
ID: 1467910
Yes and No if ctlWinsock is a Module Wide variable (declared in the General Declarations section of the class) then yes you would put the above line in the terminate event.
If the variable is a procedure wide variable then put the above line as the last line in the procedure.
0
 
LVL 2

Author Comment

by:peterwest
ID: 1467911
Hi again,

The ctlWinsock variable is in general declarations as it's referenced in mutiple procedures within the class module - i've had the releasing code in place for a while now and everything seems a lot more stable now.

Thanks

Pete

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now