Solved

Releasing of Class Objects??

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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 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…

731 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