[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

Releasing of Class Objects??

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
peterwest
Asked:
peterwest
  • 3
  • 2
1 Solution
 
JagarCommented:
Use the terminate Event of the class and set the object reference to nothing
0
 
JagarCommented:
You posted this question twice delete the other one before someone answer it.
0
 
peterwestAuthor Commented:
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
 
JagarCommented:
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
 
peterwestAuthor Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now