HOME

TheInfoList



OR:

Cleanup Stack is a concept widely used in Symbian OS. It is most suitable to use in places where
dynamic memory Memory management is a form of resource management applied to computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and free it for reuse when ...
is used (allocated) in programming. The problem with dynamic memory is the sole discretion of the underlying OS whether the request for memory allocation shall succeed or not.
Application Application may refer to: Mathematics and computing * Application software, computer software designed to help the user to perform specific tasks ** Application layer, an abstraction layer that specifies protocols and interface methods used in a c ...
s (Requester of memory) must be prepared to handle the rejection. In large programs dynamic memory is used almost everywhere. If an application frequently adds the code to handle this failure then it will increase the code size significantly. Symbian is used mostly on
phone A telephone is a telecommunications device that permits two or more users to conduct a conversation when they are too far apart to be easily heard directly. A telephone converts sound, typically and most efficiently the human voice, into ele ...
s where this increase in the code size will further amplify the memory allocation failures. Symbian features an ingenious solution to that problem. When an application notes a memory allocation may fail, it places the earlier allocated memory address to a location which Symbian is aware of. That location is called Cleanup Stack. In the event of failure, Symbian knows that whatever resource is placed on the Cleanup Stack needs be freed. This way all the resources are freed when a program crashes (or Leaves). This freeing is performed automatically by the Symbian OS. Applications die peacefully without worrying who would clean up the mess left after them. Cleanup stack make an idea to keep a copy of pointer to allocated memory and all elements from the cleanup stack are popped out and destroyed by using Push(), Pop(), and PopAndDestroy(). For example, CleanupStack::PushL(ptr) CleanupStack::Pop() CleanupStack::PopAndDestroy() Symbian OS {{operating-system-stub