First look at the code
IChildList is the pointer variable of CArrayPtrFlat <CXmlNode> *
CXmlNode * CXmlNode: AddChildNote (const TDesC & aNodeName)
{
CXmlNode * aNode = CXmlNode: NewL (aNodeName );
This-> iChildList-> AppendL (aNode );
Return aNode;
}
----
CXmlNode * node = doc-> Root ();
CArrayFixFlat <TInt> * sels = this-> GetSelectionsNewL (aListBox );
CleanupStack: PushL (sels );
For (TInt I = 0; I <sels-> Count (); I ++)
{
TPtrC pId = (* this-> iIdList) [I];
TPtrC pName = (* this-> iNameList) [I];
TPtrC pPhone = (* this-> iPhoneList) [I];
CXmlNode * aNode = node-> AddChildNote (bufPhone );
CXmlNode * idNode = aNode-> AddChildNote (bufId );
IdNode-> SetValue (pId );
CXmlNode * nameNode = aNode-> AddChildNote (bufName );
NameNode-> SetValue (pName );
CXmlNode * numNode = aNode-> AddChildNote (bufNum );
NumNode-> SetValue (pPhone );
}
After I create a node using the above Code, if I delete the node, the variable iChildList is also deleted,
In this case, I want to delete the object in iChildList, but the object in iChildList may also have iChildList.
For the image tree, I used iChildList. Reset (). When I wanted iChildList to call Reset (), every time I delete a variable, I would call this variable.
The Destructor achieves the effect of deleting all variables, but it does not actually do that, and the memory overflows.
Later
Void CXmlNode: FreeChildNote ()
{
For (TInt I = this-> iChildList-> Count ()-1; I> = 0; I --)
{
CXmlNode * aNode = this-> iChildList-> At (I );
ANode-> FreeChildNote ();
Delete aNode;
This-> iChildList-> Delete (I );
}
}
In this way, the release will be okay.
In the experiment again, only the first-level object is added, that is, the object is not saved in the object.
For (TInt I = 0; I <sels-> Count (); I ++)
{
TPtrC pId = (* this-> iIdList) [I];
TPtrC pName = (* this-> iNameList) [I];
TPtrC pPhone = (* this-> iPhoneList) [I];
CXmlNode * aNode = node-> AddChildNote (bufPhone );
// CXmlNode * idNode = aNode-> AddChildNote (bufId );
// IdNode-> SetValue (pId );
// CXmlNode * nameNode = aNode-> AddChildNote (bufName );
// NameNode-> SetValue (pName );
// CXmlNode * numNode = aNode-> AddChildNote (bufNum );
// NumNode-> SetValue (pPhone );
}
Change the remaining code comments and release to reset. The result is still incorrect. It seems that this Reset cannot be trusted.
Supplement: I still don't know about this dynamic array. Later I used ResetAndDestroy () to release it.
No problem with the image.
Anping 2009 @ original
Qi_jianzhou@126.com