关于TList内存释放问题?
失落的羊 2006-08-26 09:46:01 在使用控件数组的时候:
MyVCL1 = new TList;//创建Tlist对象
for(i= 0 ; i < 3;i++)
{
TGroupBox *GroupBoxNow = new TsuiGroupBox(this);
GroupBoxNow->Parent =Form1;
GroupBoxNow->Top =bTop;
GroupBoxNow->Left =bLeft +i*(bWidth +50);
GroupBoxNow->Height =bHeight;
GroupBoxNow->Width =bWidth;
MyVCL1->Add(GroupBoxNow);
}
delete MyVCL1; //删除Tlist对象
当删除Tlist对象的时候,需不需要遍历TList删除每个Item.
BCB自带的一个例子说是要:
// Clean up ?must free memory for the items as well as the list
for (int i = 0; i < MyList->Count; i++)
{
AStruct = (PAList) MyList->Items[i];
delete AStruct;
}
delete MyList;
}