Page 1 of 1

How to Destroy Objects created using CreateObject()

PostPosted: Mon Dec 01, 2008 6:10 am
by anserkk
Hi all,

How do I destroy an object created using CreateObject, so that I can ensure there is no Resource/Memory leak

For Eg

Code: Select all  Expand view
oConnection:=CreateObject("ADODB.Connection")
oRecSet:=CreateObject(""ADODB.RecordSet"")


In the above given eg. Which is the right way to kill/destroy the objects

Code: Select all  Expand view
oConnection:End()
oConnection:=NIL

oRecSet:End()
oRecSet:=NIL


I would like to know whether the oObject:End() followed by oObject:=NIL is the right method or not. Or is there any other way to do the same

Regards

Anser

Re: How to Destroy Objects created using CreateObject()

PostPosted: Mon Dec 01, 2008 8:35 am
by Enrico Maria Giordano
OLE objects get automatically released at the end of their lifetime (ie. at the end of the function for local variables). You don't need to explicity release them.

EMG

PostPosted: Mon Dec 01, 2008 10:31 am
by Antonio Linares
Enrico,

Previously it was required to set them to nil (no need to call :End())

Maybe this have changed recently.

PostPosted: Mon Dec 01, 2008 11:46 am
by Enrico Maria Giordano
It seems not required since 2002:

2002-05-10 17:47 UTC-0800 Ron Pinkas <ron@ronpinkas.com>
* source/rtl/win32ole.prg
+ Now allows return parameter to return OLE object.
+ Added support for SQL NULL.
- Removed the need for :End() deinitialization is automated.

* tests/pp.prg
+ Added (under #ifdef WIN): EXTERN CreatObject

* tests/testole.prg
- Removed :End() calls.


EMG

PostPosted: Mon Dec 01, 2008 11:49 am
by anserkk
Thankyou Mr.Antonio & Mr. Enrico for your advices.

Regards

Anser