The reset method of CArrayPtrFlat

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.