diff -r 4816d766a08a -r f345bda72bc4 Symbian3/PDK/Source/GUID-72E1F91B-173B-5F45-B9FF-42FD5F45438C.dita --- a/Symbian3/PDK/Source/GUID-72E1F91B-173B-5F45-B9FF-42FD5F45438C.dita Tue Mar 30 11:42:04 2010 +0100 +++ b/Symbian3/PDK/Source/GUID-72E1F91B-173B-5F45-B9FF-42FD5F45438C.dita Tue Mar 30 11:56:28 2010 +0100 @@ -1,48 +1,48 @@ - - - - - -How -to pop and destroyThis document describes how to pop and destroy objects on the cleanup -stack. -

In general, it is recommended that any objects which are accessed only -through an automatic pointer are pushed onto the cleanup stack immediately, -before being used, and only popped before they must be destroyed.

-

You can use the single function CleanupStack::PopAndDestroy() to -both pop the object from the cleanup stack and destroy it. This operation -is the usual thing to do when an object on the cleanup stack has been finished -with.

-void doExampleL() - { - // allocate and leave if could not - CExample* myExample = new (ELeave) CExample; - - // this cannot leave - no protection needed - myExample->iInt = 5; - - // do something that might leave, protected by cleanup stack - CleanupStack::PushL(myExample); // push pointer to stack - - myExample->DoSomethingL()); // something that might leave - - // pop from cleanup stack, and destroy, in one operation - CleanupStack::PopAndDestroy(); - } -
Note
    -
  • Pop() on -its own is nevertheless useful: it is safe to pop an object from the cleanup -stack when you are sure that it will either be destroyed, or a reference stored -to it, before any operations are performed on it which might leave. This way, -an object can never be orphaned (which is our aim). In the former case, you -get pop-and-destroy all in one, which it is worthwhile for the system to provide. -In the latter case, you need to store a pointer. This is what happens, for -instance, in two-phase construction.

  • -
+ + + + + +How +to pop and destroyThis document describes how to pop and destroy objects on the cleanup +stack. +

In general, it is recommended that any objects which are accessed only +through an automatic pointer are pushed onto the cleanup stack immediately, +before being used, and only popped before they must be destroyed.

+

You can use the single function CleanupStack::PopAndDestroy() to +both pop the object from the cleanup stack and destroy it. This operation +is the usual thing to do when an object on the cleanup stack has been finished +with.

+void doExampleL() + { + // allocate and leave if could not + CExample* myExample = new (ELeave) CExample; + + // this cannot leave - no protection needed + myExample->iInt = 5; + + // do something that might leave, protected by cleanup stack + CleanupStack::PushL(myExample); // push pointer to stack + + myExample->DoSomethingL()); // something that might leave + + // pop from cleanup stack, and destroy, in one operation + CleanupStack::PopAndDestroy(); + } +
Note
    +
  • Pop() on +its own is nevertheless useful: it is safe to pop an object from the cleanup +stack when you are sure that it will either be destroyed, or a reference stored +to it, before any operations are performed on it which might leave. This way, +an object can never be orphaned (which is our aim). In the former case, you +get pop-and-destroy all in one, which it is worthwhile for the system to provide. +In the latter case, you need to store a pointer. This is what happens, for +instance, in two-phase construction.

  • +
\ No newline at end of file