Circular reference problems with class modules

G

Guest

Hi all,

I have three class modules that make up a simple object model, which
for ease of explanation I'll call:

# - clsMain
# - clsCollection
# - clsItem

clsCollection has a parent property that refers to clsMain.
clsItem has a parent property that refers to clsCollection

So far so good, but I'm having real trouble understanding how to
release the references to the parent objects correctly. I've heard
of "teardown" methods but can't find a good explanation or code-
snippet anywhere (and boy have I looked!). Currently my code tries to
release the references in the Class Terminate events as follows,
which I'm certain is incorrect.

-------------------------------------
(From clsItem)
Private mobjParent as clsCollection 'Module-Level Declaration

Sub Class_Terminate()
Set mobjParent = Nothing
End Sub

-------------------------------------
(From clsCollection)
Private mcolItems as collection 'Module-Level Declaration

Sub Class_Terminate()
Set mcolItems = nothing
End sub
-------------------------------------

Can anyone help or point me in the right direction? Apologies if I
haven't been clear enough, but you need to take into account I'm a
little confused myself! ;)

Many thanks in advance,

Stuart
 
G

Guest

Hi Alex,

Many thanks for the link. It took me a fair bit of time to get my head
around it, but at least I can say I understand how it all works now. Far
better than just blindly cutting and pasting an example! ;)

Cheers,

Stuart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top