Cleanup stack
Cleanup Stack is a concept widely used in Symbian OS. It is most suitable to use in places where dynamic memory is used (allocated) in programming. The problem with the dynamic memory is that it is solely on the discretion of the underlying OS whether the request for the memory will succeed or not. Applications (Requester of memory) must be prepared to handle the rejection. In large programs dynamic memory is used almost everywhere. If application adds the code to handle this failure all the time then it will increase the code size significantly. As Symbian is used mostly on phones where this increase in the code size will further amplify the memory allocation failures. Symbian has an ingenious solution to that problem. When application see that a memory allocation may fail, it places the earlier allocated memory address to a location which Symbian is aware. That location is called Cleanup Stack. In the event of failure, Symbian knows that whatever is placed on the Cleanup Stack I need to free that resource. This way all the resources are freed when program crashes (or Leaves). This freeing is done by the Symbian OS. Applications die peacefully without worrying who will clean up the mess.