typedef struct {
char *u8_testStep;
char *u8_functionTested;
char *u8_testDescription;
char *u8_expectedResponse;
char *u8_packetTx;
char *u8_packetRx;
char *u8_passFail;
char *u8_comment;
}T_testStepDetails;
为类型创建的列表T_testStepDetails
:--
QList<T_testStepDetails>* testCaseStepslist = new QList<T_testStepDetails>();
QString strTemp;
T_testStepDetails *testStepMessageBuffer = new T_testStepDetails;
将内存分配给以下各项T_testStepDetails
:----
testStepMessageBuffer->u8_testStep = new char[strTemp.length()];
// copy value to the pointer
qstrcpy(testStepMessageBuffer->u8_testStep, strTemp.toStdString().c_str());
附加到列表中:---
testCaseStepslist->append(*testStepMessageBuffer);
空闲内存:----
if(!list.isEmpty())
{
qDeleteAll(list);
list.clear();
}
所以释放内存上述步骤足以防止内存泄漏?
或者对于列表中的每个类型的结构,我必须为我为其动态分配内存T_testStepDetails
的内部成员释放内存char*
?