PDA

Click to See Complete Forum and Search --> : Question regarding CreateObject


lychew
Apr 24th, 2000, 01:18 PM
I was having a discussion with my friends regarding this. From what i comprehend, when we write the code as

set obj= server.createobject("CDONTS.NewMail")

A new object(all the classes and properties in it) will be created every each time. But my friend think that if the statement has been used during application on start, this will only create a reference to the class of the object with another new layer consisting the data. Which of this is true or neither is true??

And what would happen if we don't set the object = nothing after we have us the object?? Will it be demolish after a certain period of time or just reside in the memory??

Somebody please help to answer this. Thanks.

Ianpbaker
Apr 24th, 2000, 04:45 PM
Hello Iychew

As To the Set Object to nothing You are Correct.

If You Don't set it to nothing it will still stay In memory And will cause Problems If your site gets Hit enough.

As For your other problem as far as I know it creates A new instance each time.

Hope this helps

Ian

[Edited by Ianpbaker on 04-25-2000 at 10:46 AM]

HarryW
Apr 24th, 2000, 06:37 PM
I don't know for sure, but I reckon you're right, you get a new object every time. I think if you equate one instance of the class to another, like

objObject1 = objObject2

then it will do like your friend says, make objObject1 a reference to objObject2, since you can't copy objects like user-defined types. If you're just instantiating a new object of the same class then I would have thought you got a new, seperate object.

OmegaJunior
May 1st, 2000, 05:14 PM
Greetings,

If in Application_OnStart an object is set, it will be reset when a page sets that same object. It will first be terminated, then it will be initialised.

If the object variable is declared in the page, setting it will make a new object for every page. It will remain in memory until the visitor during whoms visit the object is created quits. Quitting is done by timing out or using the abandon method.

If the object variable is declared in global.asa, setting it will reinitialise that variable. If the object's scope is session, there will be a new object for every session. If the scope is application, there will be only one object for every user. Setting it in the page then most likely leads to errors for other users.

If you don't set an object to nothing, it will reside in memory until the session or application quits. This could lead to memory hogs. COULD. Might not. Depends on you. If you don't use sessions nor a global.asa, objects reside in memory as long as the page is wanted (or in server cache). Effectively the object is killed on time-out.

Setting to nothing affects the object where it is declared. Setting application-scope objects to nothing renders them inaccessible to all users. Setting session-scope objects to nothing renders them useless to one user for the rest of the session (should be reaccessible, is not). Setting page objects to nothing clears up memory for that page.

Hope this helps.

lychew
May 2nd, 2000, 10:16 AM
Thanks guys...