?
Solved

Releasing of Class Objects??

Posted on 1998-08-05
5
Medium Priority
?
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
Jagar earned 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

770 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