Cleanup stack
![]() | This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)
|
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 dynamic memory is the sole discretion of the underlying OS whether the request for memory allocation shall succeed or not. Applications (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 phones 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()
References
- Articles with short description
- Short description with empty Wikidata description
- Articles with topics of unclear notability from July 2024
- All articles with topics of unclear notability
- Articles lacking sources from July 2024
- All articles lacking sources
- Articles with multiple maintenance issues
- Symbian OS
- All stub articles
- Operating system stubs