Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Objects to nothing sets others to nothing also

Status
Not open for further replies.

pamam

Programmer
Sep 13, 2001
12
0
0
US
When I create an object using Server.CreateObject e.g.

set x = Sever.CreateObject("y")

then save it in Session("z")

set Session("z") = x

then set x to nothing the session("z") also is nothing

set x = nothing

now session("z") is also nothing

Should this happen with a proper object??
y is our own automation object, but I'm thinking that it is not behaving correctly.
 
pamam

what are you trying to do?

the code above is very confusing ..............


Aaron
 
It is immaterial what the code is trying to do. This is a conceptual question. And that is if I create an object in ASP using server.createobject, then store it in a session variable, then delete the originally cretaed object by setting it to nothing, should the session object also be null at that time or not???????

My thoughts are that the object will have been addRef'd twice, once on creation and once when stored in the session object. So that when I delete the original object it will be Release'd once and the session object should still be valid.

NMy experience with some of our home grown objects is that does not work this way.

Mel

 
That is because you are setting Session Z to be a reference to Object X, not a "NEW" instance of object X. So, When you destroy X, Z is destroyed too. Try adding the NEW keyword on this line:

Code:
set Session("z") = new x

However, not all objects support the new keyword.
 
Since "x" is an object pointer and not a class name
set session("z") = new x does not work at all, I tried it!!

Also according to MSDN when you assign a new variable say newvar by setting it such:
set newvar = x, then newvar gets a pointer to x and the object is not deleted untill all vars holding pointers are set to nothing in one way or another. If this was not true you would never be able to swap objects in a list to order them.
tmp = a
a = b // this would destroy "tmp" seeing that the contents
// of "a" are deleted and "a" now becomes equal to "b"
b = tmp // this would then set "b" = to nothing and
// likewize set "a" to nothing also
and this must work or it would break all programming premisses.

So the more I'm thinking about it the more I'm thinking on the line of our objects are not working per the COM spec for automation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top