Free after GetBlob
Free after GetBlob
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
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
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.
The queryDB is a TMyQuery object with these SQL:
There is an INSERT SQL in queryDB:
This is the DDL
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?
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();
Code: Select all
SELECT * FROM thisTable WHERE key=:key;
Code: Select all
INSERT INTO thisTable VALUES (...) ON DUPLICATE KEY UPDATE PicField=:PicField
Code: Select all
CREATE TABLE `thisTable` (
`key` VARCHAR(36),
`PicField` BLOB
)ENGINE=InnoDB;
Am I handling blob properly?