Page 1 of 1

Free after GetBlob

Posted: Wed 09 Jun 2010 17:28
by 97itr217
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

Posted: Thu 10 Jun 2010 11:07
by Dimon
You should not free blob object returned by the GetBlob method.

Posted: Tue 27 Jul 2010 18:16
by 97itr217
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?

Posted: Wed 28 Jul 2010 09:29
by Dimon
I could not reproduce the problem.
Please send me a complete small sample to dmitryg*devart*com to demonstrate it.

Posted: Wed 28 Jul 2010 18:50
by 97itr217
Sample app sent.

Posted: Fri 30 Jul 2010 17:18
by 97itr217
Dimon,
Any progress on this?

Posted: Mon 02 Aug 2010 14:07
by Dimon
Unfortunally I have not received your email. Please, send it to me once more.

Posted: Tue 03 Aug 2010 14:52
by 97itr217
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.

Posted: Wed 04 Aug 2010 10:17
by Dimon
We have answered you by e-mail.

Posted: Wed 04 Aug 2010 15:10
by 97itr217
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()?

Posted: Thu 05 Aug 2010 08:36
by Dimon
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.

Posted: Thu 05 Aug 2010 15:56
by 97itr217
Great! TMyQuery->Refresh() works.

Posted: Thu 05 Aug 2010 16:15
by Dimon
I am happy that this problem has been solved.