Tracking class instances 
Author Message
 Tracking class instances

Gedday VBers,

I am having trouble releasing my class references, well that is what i
think is causing my program to crash on exit (even though when I check
the class references they are set to "Nothing")

Question 1.  If typename(objMyClass) returns  "Nothing",  does that mean
the class has been fully released?

Queston 2.  If i set the Parent and Application objects of the class, is
there a required order which i should de-reference all these class
objects?  
Eg:     Set objMyClass.Parent = Nothing                 'is this required?
        Set objMyClass.Application = Nothing            'is this required??    
        Set objMyClass = Nothing

'----------------//------------
Private Class_terminate()
        Set mobjParent = Nothing                'module level parent object
        Set mobjApplication = Nothing           'app. object app. object

        Set <Any dependent classes> = Nothing
end sub

Would you say the above code would de-reference all my objects
correctly?

Question 3. Is there more sofisticated debugging tools which will enable
me to track my class references?   I had high hopes for the VB5 stack
debugging facility, but it doesnt  seem all that useful in tracking
class references.  

(i am currently coding in VB4, but am in the process of transferring
across to VB5)

Thank you for any comments on these issues,

Regards Carl.



Tue, 12 Dec 2000 03:00:00 GMT  
 Tracking class instances

--
Ron Ruble
Raffles Software Development, Inc.
Patient - Doctor, it hurts when I do this!
Doctor - Then don't do that.

Quote:

>Gedday VBers,

>I am having trouble releasing my class references, well that is what i
>think is causing my program to crash on exit (even though when I check
>the class references they are set to "Nothing")

>Question 1.  If typename(objMyClass) returns  "Nothing",  does that mean
>the class has been fully released?

No; it means that variable objMyClass holds no reference to an object.
If two object variables point to the same object, setting one to
Nothing has no effect on the object being referred to.
Setting an Object to Nothing is the same as calling IUnknown::Release.
All it does is decrement the reference count on the instance. Only
when that reference count reaches zero is the object destroyed.

Quote:
>Queston 2.  If i set the Parent and Application objects of the class, is
>there a required order which i should de-reference all these class
>objects?
>Eg: Set objMyClass.Parent = Nothing 'is this required?
> Set objMyClass.Application = Nothing 'is this required??
> Set objMyClass = Nothing

No for all three. It doesn't hurt anyhting, but any Private variables
belonging to your class object are released when the object
is terminated anyway. And setting Private variables to Nothing
only works is you have no external references to them stored in
other variables.

Quote:
>'----------------//------------
>Private Class_terminate()
> Set mobjParent = Nothing 'module level parent object
> Set mobjApplication = Nothing 'app. object app. object

> Set <Any dependent classes> = Nothing
>end sub

>Would you say the above code would de-reference all my objects
>correctly?

It's correct, but again the objects would not be released until all other
references (if any) to these same objects are released.

Quote:
>Question 3. Is there more sofisticated debugging tools which will enable
>me to track my class references?   I had high hopes for the VB5 stack
>debugging facility, but it doesnt  seem all that useful in tracking
>class references.

Can't help you on other tools; they exist, but I haven't used them.
What is useful is setting trace code (debug.print) in terminate
and Initialize routines. If you have a debug.print in your Terminate
event, for example, and setting an object reference to Nothing
doesn't fire the event, then you have at least one other reference
to the object.
If you're having a lot of trouble with managing object references,
you might try redesigning your objects.
By creating interface functions and broker functions, you
can limit the ways the clients can use your objects. DAO, for
example, does this by requiring you to use Database objects to
create Recordset objects.
Quote:
>(i am currently coding in VB4, but am in the process of transferring
>across to VB5)

>Thank you for any comments on these issues,

>Regards Carl.



Wed, 13 Dec 2000 03:00:00 GMT  
 Tracking class instances

Gedday VBers,

I am having trouble releasing my class references, well that is what i
think is causing my program to crash on exit (even though when I check
the class references they are set to "Nothing")

Question 1.  If typename(objMyClass) returns  "Nothing",  does that mean
the class has been fully released?

Queston 2.  If i set the Parent and Application objects of the class, is
there a required order which i should de-reference all these class
objects?  
Eg:     Set objMyClass.Parent = Nothing                 'is this required?
        Set objMyClass.Application = Nothing            'is this required??    
        Set objMyClass = Nothing

'----------------//------------
Private Class_terminate()
        Set mobjParent = Nothing                'module level parent object
        Set mobjApplication = Nothing           'app. object app. object

        Set <Any dependent classes> = Nothing
end sub

Would you say the above code would de-reference all my objects
correctly?

Question 3. Is there more sofisticated debugging tools which will enable
me to track my class references?   I had high hopes for the VB5 stack
debugging facility, but it doesnt  seem all that useful in tracking
class references.  

(i am currently coding in VB4, but am in the process of transferring
across to VB5)

Thank you for any comments on these issues,

Regards Carl.



Sun, 17 Dec 2000 03:00:00 GMT  
 Tracking class instances

Carl

I should think you are having problems if you're holding references to
parents in their children. This can lead to all sorts of problems unless
you carefully tear down the references.

The usual reason for holding client references within a server is to
implement call-backs rather than use events. If you are using
call-backs, make sure that you have an explicit method of the server
that the client can call to get it to release its reference to the
client. Then the client's client can set its reference to the client to
Nothing and the client will disappear. Follow it?

ClassA uses ClassB with call-backs. At some time, ClassA will
instantiate ClassB and pass a reference to itself through a
CallbackClient property (so that ClassB can call back into ClassA).
There is now a double reference to ClassA (one from ClassA's client and
another from ClassB).

If ClassA's client sets its reference to ClassA to Nothing, the ClassA
Terminate event will NOT fire because there is still an outstanding
reference (from ClassB). What ClassA must do is to implement a method
(say TearDown) which sets the CallbackClient property in ClassB to
Nothing. Now ClassA can destroy ClassB and now ClassA's client can
destroy ClassA.

If you're not using call-backs, don't hold references to clients and
under no circumstances set Parent or Application properties!

Regards
{*filter*}

Quote:

>Gedday VBers,

>I am having trouble releasing my class references, well that is what i
>think is causing my program to crash on exit (even though when I check
>the class references they are set to "Nothing")

>Question 1.  If typename(objMyClass) returns  "Nothing",  does that
mean
>the class has been fully released?

>Queston 2.  If i set the Parent and Application objects of the class,
is
>there a required order which i should de-reference all these class
>objects?
>Eg: Set objMyClass.Parent = Nothing 'is this required?
> Set objMyClass.Application = Nothing 'is this required??
> Set objMyClass = Nothing

>'----------------//------------
>Private Class_terminate()
> Set mobjParent = Nothing 'module level parent object
> Set mobjApplication = Nothing 'app. object app. object

> Set <Any dependent classes> = Nothing
>end sub

>Would you say the above code would de-reference all my objects
>correctly?

>Question 3. Is there more sofisticated debugging tools which will
enable
>me to track my class references?   I had high hopes for the VB5 stack
>debugging facility, but it doesnt  seem all that useful in tracking
>class references.

>(i am currently coding in VB4, but am in the process of transferring
>across to VB5)

>Thank you for any comments on these issues,

>Regards Carl.



Sun, 17 Dec 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Keeping track of class instances

2. newbie: private class variables are visible in class instances

3. Find out if somebody make an instance of a Class without having access to the Class

4. nested class inherits containing class accessing private instance members

5. instance a class from its class name

6. Script Debugger - tracking errors in class modules

7. tracking VB class object memory usage

8. Instances of custom class modules

9. Instancing Class Module

10. class instancing settings in Access VBA?

11. instance of class module can't see own type

12. How to close an instance of a class

 

 
Powered by phpBB® Forum Software