FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to Destroy Objects created using CreateObject()
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
How to Destroy Objects created using CreateObject()
Posted: Mon Dec 01, 2008 06: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

oConnection:=CreateObject("ADODB.Connection")
oRecSet:=CreateObject(""ADODB.RecordSet"")


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

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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to Destroy Objects created using CreateObject()
Posted: Mon Dec 01, 2008 08: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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to Destroy Objects created using CreateObject()
Posted: 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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
How to Destroy Objects created using CreateObject()
Posted: 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
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
How to Destroy Objects created using CreateObject()
Posted: Mon Dec 01, 2008 11:49 AM

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

Regards

Anser

Continue the discussion