Symbian3/SDK/Source/GUID-E5A83EF3-948B-5729-A2CD-3644E803520B.dita
changeset 7 51a74ef9ed63
parent 0 89d6a7a84779
equal deleted inserted replaced
6:43e37759235e 7:51a74ef9ed63
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept id="GUID-E5A83EF3-948B-5729-A2CD-3644E803520B" xml:lang="en"><title>Cleanup
       
    13 Support Overview</title><shortdesc>Provides idioms to handle program exceptions, and to clean up memory
       
    14 when exceptions occur</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    15 <section id="GUID-AD5DD150-BB36-4ABC-AF10-D47DEEBE6EED"><title>Architectural relationships</title> <p>Symbian platform's
       
    16 clean up strategy is closely tied to its general class types, particularly
       
    17 classes derived from <xref href="GUID-8F6FE089-E2A8-30F4-B67E-10F286347681.dita"><apiname>CBase</apiname></xref>.</p> </section>
       
    18 <section id="GUID-A839CBBC-864A-40E0-8BCF-50BB307A3D03"><title>Description</title> <p>The API has three key concepts: exception
       
    19 handling, cleanup stack, and general cleanup item. </p> <p><b>Exception
       
    20 handling</b> </p> <p>Symbian platform does not use standard C++ exceptions
       
    21 (<codeph>try</codeph>, <codeph>catch()</codeph> blocks), but supplies its
       
    22 own idioms. An exception is referred to as a <i>leave</i>.</p> <p>The <i>trap
       
    23 harness</i> defines a point in code that will be immediately jumped to if
       
    24 a leave occurs. The trap harness is set using the <xref href="GUID-3F2CDC74-2568-371C-9D8E-34A66A619226.dita"><apiname>TRAP</apiname></xref> and <xref href="GUID-57895C34-AD00-35E1-9BF8-478653056383.dita"><apiname>TRAPD</apiname></xref> macros.</p> <p>Leaves
       
    25 are raised through calling functions provided by the System Static Functions
       
    26 API <codeph>User</codeph> class, principally <xref href="GUID-C197C9A7-EA05-3F24-9854-542E984C612D.dita#GUID-C197C9A7-EA05-3F24-9854-542E984C612D/GUID-ABF0FC5C-3334-3761-893D-D836B2EE0541"><apiname>User::Leave()</apiname></xref>.
       
    27 Many system functions can result in leaves. Leaves may also be raised in user
       
    28 code.</p> <p><b>Cleanup
       
    29 stack</b> </p> <p>If a leave occurs, any heap allocated resources, such as
       
    30 objects created through <codeph>new()</codeph>, referred to only through automatic
       
    31 pointer variables will be orphaned on the heap, causing a memory leak. To
       
    32 prevent such leaks, it is necessary for the program to record any such objects,
       
    33 so that, on the event of a leave, the system can automatically find and clean
       
    34 them up. The cleanup stack is the means by which this is done. </p> <p>The
       
    35 cleanup stack is provided by <xref href="GUID-0DD554D7-B9B1-3FD3-898F-4D855144FCEA.dita"><apiname>CleanupStack</apiname></xref>. </p> <p>GUI
       
    36 applications have a cleanup stack supplied to them by the application framework.
       
    37 Other applications must explicitly create a cleanup stack using <xref href="GUID-17AC7BAD-1C03-3729-BCC6-F5B28B32E99D.dita"><apiname>CTrapCleanup</apiname></xref>.</p> <p><b>General cleanup item</b> </p> <p>By default, the cleanup stack only handles <xref href="GUID-8F6FE089-E2A8-30F4-B67E-10F286347681.dita"><apiname>CBase</apiname></xref> -based
       
    38 classes, and untyped (<codeph>TAny*</codeph>) objects that can be cleaned
       
    39 up by a simple memory free call. The general cleanup item allows other types
       
    40 of object to put on the cleanup stack, by making the caller specify a function
       
    41 that is to be called to perform cleanup on the object.</p> <p>The general
       
    42 cleanup item interface is provided by <xref href="GUID-CD0A798E-7E42-3689-8E86-F5FD43C758FC.dita"><apiname>TCleanupItem</apiname></xref>.</p> <p>Template
       
    43 functions are provided as shortcuts to constructing a <xref href="GUID-CD0A798E-7E42-3689-8E86-F5FD43C758FC.dita"><apiname>TCleanupItem</apiname></xref> and
       
    44 pushing it onto the cleanup stack. These functions are <codeph>template &lt;class
       
    45 T&gt; void              CleanupDeletePushL(T*)</codeph>, <codeph>template &lt;class
       
    46 T&gt; void              CleanupClosePushL(T&amp;)</codeph>, and <codeph>template
       
    47 &lt;class T&gt; void              CleanupReleasePushL(T&amp;)</codeph>.</p> </section>
       
    48 <section id="GUID-F348A3AA-37A8-4489-89BD-26DF97F026E2"><title>See also</title> <p><xref href="GUID-FBE448A4-4728-5EE5-84F2-4790735857B3.dita">Basic
       
    49 Types Overview</xref> </p> <p><xref href="GUID-FF8F5D97-7D37-5F6B-84A3-C064E2FD53E0.dita">System
       
    50 Static Functions Overview</xref> </p> </section>
       
    51 </conbody></concept>