How to Destroy Objects created using CreateObject()

How to Destroy Objects created using CreateObject()

Postby anserkk » Mon Dec 01, 2008 6:10 am

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
User avatar
anserkk
 
Posts: 1329
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to Destroy Objects created using CreateObject()

Postby Enrico Maria Giordano » Mon Dec 01, 2008 8:35 am

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
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Mon Dec 01, 2008 10:31 am

Enrico,

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

Maybe this have changed recently.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Enrico Maria Giordano » Mon Dec 01, 2008 11:46 am

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
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby anserkk » Mon Dec 01, 2008 11:49 am

Thankyou Mr.Antonio & Mr. Enrico for your advices.

Regards

Anser
User avatar
anserkk
 
Posts: 1329
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 92 guests