This page was last modified 12:05, 12 December 2007.
Cleanup stack support for non-CBase classes
From Forum Nokia Wiki
The discussion of clean up so far has assumed objects to be cleaned up are derived from CBase, with clean up by invoking delete. Other classes need explicit cleanup support to be provided by the programmer.
The cleanup stack supports other types of object by two further overloaded versions of CleanupStack::PushL(). You may push:
- a TAny*: such objects are destroyed by invoking User::Free() on the pointer pushed — note that this is less powerful: it simply frees the memory, without calling the C++ destructor
- a TCleanupItem: an object of this type encapsulates a pointer to the object to be pushed, and a pointer to a function that provides cleanup for that object.
Some utility functions are provided that make construction of a suitable TCleanupItem easy.
Example: RPointerArray
RPointerArray can be pushed in the CleanupStack and safely destroyed by making a TCleanupItem and a static function for it. In this example the array contains HBufC descriptors.
// static cleanup function static void PointerArrayCleanup( TAny* aArray ) { static_cast<RPointerArray<HBufC>*>( aArray )->ResetAndDestroy(); } RPointerArray<HBufC> array; ... TCleanupItem arrayCleanup( PointerArrayCleanup, &array ); CleanupStack::PushL( arrayCleanup ); ... CleanupStack::PopAndDestroy(); // arrayCleanup
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem of Destorying CMsvEntry, thank you:D | autumnsea | Web Technologies and Multimedia Content- Web 技术和多媒体内容 | 3 | 2006-10-08 08:49 |
| Need help. SMS observer keeps tripping. | Donnieng | General Symbian C++ | 6 | 2007-07-08 20:55 |
| CEikwin not inputting input on emulator | ranolivi | Symbian User Interface | 3 | 2004-03-02 10:27 |
| KERN EXEC 3 panic + array of descriptor issue in storing data on OnStartElement | netra | General Symbian C++ | 4 | 2008-03-05 09:30 |
| 程序调试问题 | draker | Symbian | 1 | 2005-04-18 04:28 |
