Assertion Failed: TOraObject.Free RefCount = 0

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Morelli
Posts: 15
Joined: Thu 19 Mar 2015 15:45

Assertion Failed: TOraObject.Free RefCount = 0

Post by Morelli » Tue 18 Aug 2015 14:14

Hi Folks,
I use C++ XE6 Builder with ODAC 9.5.18.

The following code looks correct but when I delete the query-Object a EAssertion (EAssertion Failed: TOraObject.Free RefCount = 0 (D:\Projects\Delphi\Dac\Common\Source\MemData.pas, Line 8977)) is rised! Why does a delete rise this Assertion!?
Is there something wrong in my code?

Code: Select all

   TOraSession* session = new TOraSession (0);
   session->Server         = "mapsrv11";
   session->Username       = "hkf14t";
   session->Password       = "hkf14t";
   session->Connected      = true;

   TOraQuery* query = new TOraQuery (0);
   query->Session          = session;

   query->SQL->Clear ();
   query->SQL->Add ((String)
         "select * from geof3044 A where " +
         "mdsys.sdo_relate(A.SHAPE, :CUTPOLY," +
         "'mask=ANYINTERACT querytype=WINDOW') = 'TRUE' or A.geofid = 4796");

   query->Params->Clear();
   query->Params->CreateParam (Db::ftObject, "CUTPOLY", Db::ptInput);

   TOraObject* oraObject = new TOraObject (0);
   oraObject->AllocObject (session->OCISvcCtx, "MDSYS.SDO_GEOMETRY");

      // Create Dummy Object
      //
      oraObject->AttrAsInteger["SDO_GTYPE"] = 2003;
      oraObject->AttrAsObject["SDO_POINT"]->IsNull = true;

      TOraArray* elemInfo = oraObject->AttrAsArray["SDO_ELEM_INFO"];
      elemInfo->ItemAsInteger[0] = 1;
      elemInfo->ItemAsInteger[1] = 1003;
      elemInfo->ItemAsInteger[2] = 1;

      TOraArray* ordinates = oraObject->AttrAsArray["SDO_ORDINATES"];
      ordinates->ItemAsFloat[0] = 1;
      ordinates->ItemAsFloat[0] = 1;
      ordinates->ItemAsFloat[1] = 1;
      ordinates->ItemAsFloat[1] = 2;
      ordinates->ItemAsFloat[2] = 2;
      ordinates->ItemAsFloat[2] = 2;
      ordinates->ItemAsFloat[3] = 2;
      ordinates->ItemAsFloat[3] = 1;

   query->ParamByName ("CUTPOLY")->AsObject = oraObject;
   query->Execute ();

   oraObject->FreeObject (true);

   delete oraObject;
   delete query;     // EAssertion Failed: TOraObject.Free RefCount = 0       (D:\Projects\Delphi\Dac\Common\Source\MemData.pas, Line 8977)
   delete session;
Thanks for your help!
Kind regards
Mike

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Assertion Failed: TOraObject.Free RefCount = 0

Post by AlexP » Wed 19 Aug 2015 07:57

Hello,

Thank you for the information, we have reproduced the problem and will investigate the reasons for this kind of behaviour. We will inform you as soon as we have any results.

Morelli
Posts: 15
Joined: Thu 19 Mar 2015 15:45

Re: Assertion Failed: TOraObject.Free RefCount = 0

Post by Morelli » Fri 28 Aug 2015 08:52

Ok, we are looking forward the results/fixes.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Assertion Failed: TOraObject.Free RefCount = 0

Post by AlexP » Fri 28 Aug 2015 09:19

No, this problem has not been fixed, we'll try to fix it in the next version

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Assertion Failed: TOraObject.Free RefCount = 0

Post by AlexP » Wed 02 Sep 2015 07:34

To solve the problem, you should call oraObject->Release() instead of delete oraObject. In addition, you need not to call the oraObject->FreeObject (true) method.

Morelli
Posts: 15
Joined: Thu 19 Mar 2015 15:45

Re: Assertion Failed: TOraObject.Free RefCount = 0

Post by Morelli » Fri 04 Sep 2015 08:20

Ok thx.

So is this usage correct:

We have a class 'AClass' with a member/field

Code: Select all

TOraObject* Geometry
.
This Object is created by calling

Code: Select all

Geometry = new TOraObject (0);
After creating the object we call N Times:

Code: Select all

Geometry->AllocObject (OracleSession->OCISvcCtx, "MDSYS.SDO_GEOMETRY");
//... do something here
Geometry->FreeObject (true);
Then the 'AClass' calls inside the destructor:

Code: Select all

TOraObject->Release () 
to delete the Geometry Object;

Is there a wrong usage or a Memory leak?
Thanks for your help!

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Assertion Failed: TOraObject.Free RefCount = 0

Post by AlexP » Mon 14 Sep 2015 10:44

As I wrote above, there is no need to call oraObject->FreeObject (true), this won't lead to Memory Leak.


P.S. You can monitor memory leaks by setting the ReportMemoryLeaksOnShutdown global variable to True.

Post Reply