Free after GetBlob

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
97itr217
Posts: 19
Joined: Tue 31 Mar 2009 14:54
Location: Canada

Free after GetBlob

Post by 97itr217 » Wed 09 Jun 2010 17:28

Got a dumb question.
Is Free() needed after GetBlob?
For example:

TBlob *myBlob = q->GetBlob("AField");
:
:
myBlob->Free(); // is this needed ???

A colleague has used Free() to fix a memory leak problem. However, if myBlob contains zero length storage, Free() crashed on the second call. It looks like the first call to Free() has corrupted some memory.
What gives?

We are using BDS2006, MyDAC 5.90.0.55
Thanks

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 10 Jun 2010 11:07

You should not free blob object returned by the GetBlob method.

97itr217
Posts: 19
Joined: Tue 31 Mar 2009 14:54
Location: Canada

Post by 97itr217 » Tue 27 Jul 2010 18:16

Thanks for your reply.
I think I am still not getting the full picture on how to do blob.
It's clear that I don't need to "Free" after "GetBlob" but the memory leak test shows that our application is leaking memory if we manipulate blob.
This is how we write to the DB.

Code: Select all

:
queryDB->Open();
:
while not program exit
{
   NewTransaction();
   queryDB->Insert();
   queryDB->FieldByName("key")->AsString = "somekey";
   if (save_pic)
   {
      TBlob *myBlob = queryDB->GetBlob("PicField");
      myBlob->write(0, pic_length, (char*)pic_buffer);
   }
   else
   {
      queryDB->FieldByName("PicField")->Clear();
   }
   myBlob->Post();
   CommitTransaction();
}
:
queryDB->Close();
The queryDB is a TMyQuery object with these SQL:

Code: Select all

    SELECT * FROM thisTable WHERE key=:key;
There is an INSERT SQL in queryDB:

Code: Select all

    INSERT INTO thisTable VALUES (...) ON DUPLICATE KEY UPDATE PicField=:PicField
This is the DDL

Code: Select all

CREATE TABLE `thisTable` ( 
  `key` VARCHAR(36),
  `PicField` BLOB 

)ENGINE=InnoDB;
If save_pic is false, the application does not seem to leak memory. However if save_pic is true, the application leaks memory dramatically.

Am I handling blob properly?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 28 Jul 2010 09:29

I could not reproduce the problem.
Please send me a complete small sample to dmitryg*devart*com to demonstrate it.

97itr217
Posts: 19
Joined: Tue 31 Mar 2009 14:54
Location: Canada

Post by 97itr217 » Wed 28 Jul 2010 18:50

Sample app sent.

97itr217
Posts: 19
Joined: Tue 31 Mar 2009 14:54
Location: Canada

Post by 97itr217 » Fri 30 Jul 2010 17:18

Dimon,
Any progress on this?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 02 Aug 2010 14:07

Unfortunally I have not received your email. Please, send it to me once more.

97itr217
Posts: 19
Joined: Tue 31 Mar 2009 14:54
Location: Canada

Post by 97itr217 » Tue 03 Aug 2010 14:52

I've just resent the sample app again, don't know why it did not get to you.
The problem has bubbled up to become a major obstacles in our testing. Could you (or your colleagues) take a look at it ASAP?
Your help is very much appreciated.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 04 Aug 2010 10:17

We have answered you by e-mail.

97itr217
Posts: 19
Joined: Tue 31 Mar 2009 14:54
Location: Canada

Post by 97itr217 » Wed 04 Aug 2010 15:10

Do you mean memory keeps growing when I insert records into table? Our app keeps inserting (when appropriate) records and could not afford a shutdown every couple of days.
Is this any way to unload memory allocated? Should I do a TMyQuery.Close()?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 05 Aug 2010 08:36

Yes, you can use TMyQuery.Close or you can create a query with a WHERE section and execute TMyQuery.Refresh to free memory for records that don't fit for this condition.

97itr217
Posts: 19
Joined: Tue 31 Mar 2009 14:54
Location: Canada

Post by 97itr217 » Thu 05 Aug 2010 15:56

Great! TMyQuery->Refresh() works.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 05 Aug 2010 16:15

I am happy that this problem has been solved.

Post Reply