代码:
typedef struct TDataStruct
{
TBuf8 <128> iData;
TInt iThreadNum;
TInt iFlag;
};
TInt CThreadEngine::ThreadFunc_1(TAny* aPtr)
{
CTestObject *ptr = (CTestObject *)aPtr;
ptr-> InitFile(1);
TInt a = 1;
TBuf8 <128> data;
TInt aErr = 0;
CArrayFixFlat <TDataStruct*> *pArray = new (ELeave) CArrayFixFlat <TDataStruct*> (50);
while (a)
{
if (pArray-> Count()> 0)
{
pArray-> Delete(0);
pArray-> Compress();
}
data.Zero();
if (ptr-> GetFileData(data,1)!= KErrNone)
{
User::InfoPrint(_L( "Thread1 GetFile Err! "));
break;
}
TDataStruct *pData = new TDataStruct;
pData-> iData.Copy(data);
pData-> iThreadNum = 0;
pData-> iFlag = 0;
pArray-> AppendL(pData);
User::After(100);
}
ptr-> CloseFile(1);
return 1;
}
这段代码的主要功能是,从文件中读取数据,然后存到pArray的数组中,再删除,目的是测试运行是否有问题,现在的情况是,运行没问题,但是系统内存不断的增长,也就是说代码:
if (pArray-> Count()> 0)
{
pArray-> Delete(0);
pArray-> Compress();
}并没有释放掉内存,请教该如何释放这段内存,非常感谢
------解决方案--------------------------------------------------------
CArrayFixFlat主要用来存储T类或R类,在堆上创建的对象应该使用CArrayPtrFlat,最后通过下面的函数释放空间:
CArrayPtrFlat::Reset()
Thsi function deletes all elements from the array and frees the memory allocated to the array buffer.
------解决方案--------------------------------------------------------
哪是肯定的了.
我的做法是:
for(TInt i=0; i <pArray-> Count(); i++)
{
pData = pArray-> at(i);
delete pData;
}
pArray-> Reset();
pArray-> Compress();
希望你能成功