Symbian3/PDK/Source/GUID-1FC0156C-7BDB-5D5B-9860-837DAB431D24.dita
changeset 5 f345bda72bc4
parent 3 46218c8b8afa
child 14 578be2adaf3e
equal deleted inserted replaced
4:4816d766a08a 5:f345bda72bc4
     7     Nokia Corporation - initial contribution.
     7     Nokia Corporation - initial contribution.
     8 Contributors: 
     8 Contributors: 
     9 -->
     9 -->
    10 <!DOCTYPE concept
    10 <!DOCTYPE concept
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    12 <concept xml:lang="en" id="GUID-1FC0156C-7BDB-5D5B-9860-837DAB431D24"><title>How to implement and use NewLC()</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>When an object is created through <codeph>NewLC()</codeph>, use <codeph>CleanupStack::PopAndDestroy()</codeph> to destroy the object when its use is complete.</p> <codeblock id="GUID-34A7790B-1FA9-58FA-83D9-A2CF6C07F2F2" xml:space="preserve">static CExample* CExample::NewLC()
    12 <concept id="GUID-1FC0156C-7BDB-5D5B-9860-837DAB431D24" xml:lang="en"><title>How to
       
    13 implement and use NewLC()</title><shortdesc>This document describes how to destroy objects created with <codeph>NewLC()</codeph>.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p>When an object is created through <codeph>NewLC()</codeph>, use <codeph>CleanupStack::PopAndDestroy()</codeph> to
       
    15 destroy the object when its use is complete.</p>
       
    16 <codeblock id="GUID-34A7790B-1FA9-58FA-83D9-A2CF6C07F2F2" xml:space="preserve">static CExample* CExample::NewLC()
    13     {
    17     {
    14     CExample* self = new (ELeave) CExample();
    18     CExample* self = new (ELeave) CExample();
    15     CleanupStack::PushL(self);
    19     CleanupStack::PushL(self);
    16     self-&gt;ConstructL();
    20     self-&gt;ConstructL();
    17     return self;
    21     return self;
    18     }</codeblock> <codeblock id="GUID-421A377A-7192-5908-A1C6-E3941046D489" xml:space="preserve">void doExampleL()
    22     }</codeblock>
       
    23 <codeblock id="GUID-421A377A-7192-5908-A1C6-E3941046D489" xml:space="preserve">void doExampleL()
    19     {
    24     {
    20     // allocate and push to cleanup stack - leave if failed
    25     // allocate and push to cleanup stack - leave if failed
    21     CExample* myExample = CExample::NewLC();
    26     CExample* myExample = CExample::NewLC();
    22     // do something that might leave
    27     // do something that might leave
    23     myExample-&gt;DoSomethingL();  
    28     myExample-&gt;DoSomethingL();  
    24     // pop from cleanup stack and destroy
    29     // pop from cleanup stack and destroy
    25     CleanupStack::PopAndDestroy(); 
    30     CleanupStack::PopAndDestroy(); 
    26     }</codeblock> </conbody></concept>
    31     }</codeblock>
       
    32 </conbody></concept>