Solved

Releasing of Class Objects??

Posted on 1998-08-05
5
174 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…

708 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

16 Experts available now in Live!

Get 1:1 Help Now