'p' was given to 'Xml_DOM_Node* pXmlDOMNode' as its parameter to the
constructor. 'pXmlDOMNode' gets destroyed by main, and (pXmlDOMNode)'s
destructor destroys the 'Xml_DOM_Node_Impl p' that was given to it. No
memory leak as long as you remember to delete the return value from
'getFirstChild()' somewhere; in our example that happens in main().
> -----Original Message-----
> From: Awasthi, Anand [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, June 12, 2001 3:33 PM
> To: '[EMAIL PROTECTED]'
> Subject: RE: wrapping Xerces API in my code !!
>
> but what about the memory leak for Xml_DOM_Node_Impl *p ;
> who will release that :
>
>
> Xml_DOM_Node* Xml_DOM_Node::getFirstChild() const
> {
>
> DOM_Node node =
> pdomnodeimpl->domnode.getFirstChild();
>
>
> Xml_DOM_Node_Impl* p = new Xml_DOM_Node_Impl;
> p->domnode = node;
> Xml_DOM_Node* pXmlDOMNode = new Xml_DOM_Node(p);
> return pXmlDOMNode;
>
> // WHO WILL release memory pointed by p
> }
>
> main () {
> Xml_DOM_Node* xmlnode2 = xmlnode1.getFirstChild();
> // do some work
> .
> .
> .
> delete xmlnode2;// caller deletes the memory
> }
>
>
> who is going to delete that ?? may be i am stupid but jst a dumb question.
>
> -----Original Message-----
> From: Adams, David [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, June 12, 2001 3:27 PM
> To: '[EMAIL PROTECTED]'
> Subject: RE: wrapping Xerces API in my code !!
>
>
> If you create an assignment operator in your class, things would be
> easier. But, to answer your question, the caller is responsible for
> freeing
> the allocated memory returned by a called function:
>
> Xml_DOM_Node* Xml_DOM_Node::getFirstChild() const
> {
> // get the node
> DOM_Node node =
> pdomnodeimpl->domnode.getFirstChild();
>
> // create your struct and wrap the node in it
> Xml_DOM_Node_Impl* p = new Xml_DOM_Node_Impl;
> p->domnode = node;
>
> // create your returnable class with the wrapped
> struct in it.
> // The caller is responsible for deleting the memory
> Xml_DOM_Node* pXmlDOMNode = new Xml_DOM_Node(p);
> return pXmlDOMNode;
> }
>
> void main(void)
> {
> .
> .
> .
> DOM_Node n; // again, some valid node
> Xml_DOM_Node_Impl* impl = new Xml_DOM_Node_Impl;
> Xml_DOM_Node xmlnode1(impl);
>
> Xml_DOM_Node* xmlnode2 = xmlnode1.getFirstChild();
> // do some work
> .
> .
> .
> delete xmlnode2;// caller deletes the memory
> }
>
>
> > -----Original Message-----
> > From: Awasthi, Anand [SMTP:[EMAIL PROTECTED]]
> > Sent: Tuesday, June 12, 2001 3:11 PM
> > To: '[EMAIL PROTECTED]'
> > Subject: RE: wrapping Xerces API in my code !!
> >
> > but what about the memory leak ( due to pointer creation with in
> function
> > body ) ??
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]