Tuesday, January 26, 2016
Consult on the thread of the memory problem
Code:
typedef struct TDataStruct
{
TBuf8 & lt; 128 & gt; iData;
TInt iThreadNum;
TInt iFlag;
};
TInt CThreadEngine :: ThreadFunc_1 (TAny * aPtr)
{
CTestObject * ptr = (CTestObject *) aPtr;
ptr- & gt; InitFile (1);
TInt a = 1;
TBuf8 & lt; 128 & gt; data;
TInt aErr = 0;
CArrayFixFlat & lt; TDataStruct * & gt; * pArray = new (ELeave) CArrayFixFlat & lt; TDataStruct * & gt; (50);
while (a)
{
if (pArray- & gt; Count () & gt; 0)
{
pArray- & gt; Delete (0);
pArray- & gt; Compress ();
}
data.Zero ();
if (ptr- & gt;! GetFileData (data, 1) = KErrNone)
{
User :: InfoPrint (_L ("Thread1 GetFile Err!"));
break;
}
TDataStruct * pData = new TDataStruct;
pData- & gt; iData.Copy (data);
pData- & gt; iThreadNum = 0;
pData- & gt; iFlag = 0;
pArray- & gt; AppendL (pData);
User :: After (100);
}
ptr- & gt; CloseFile (1);
return 1;
}
The main function of this code is to read data from the file, and then save the array pArray in, and then delete the aim is to test run if there are problems, the present situation is to run no problem, but the constant growth of system memory, That Code:
if (pArray- & gt; Count () & gt; 0)
{
pArray- & gt; Delete (0);
pArray- & gt; Compress ();
} And not freed memory, to ask how to release this memory, thanks
Reply:
CArrayFixFlat mainly used to store Class A or Class T R, the objects created on the heap should use CArrayPtrFlat, the last free space by the following function:
CArrayPtrFlat :: Reset ()
Thsi function deletes all elements from the array and frees the memory allocated to the array buffer.
Reply:
What is for sure.
My approach is:
for (TInt i = 0; i & lt; pArray- & gt; Count (); i ++)
{
pData = pArray- & gt; at (i);
delete pData;
}
pArray- & gt; Reset ();
pArray- & gt; Compress ();
I hope you can
success
Reply:
Oh, very grateful to the two replies, the question has been closed, stickers, practices such as qj7979 (qj) said!
No comments:
Post a Comment