This document describes how to destroy objects created with NewLC()
.
When an object is created through NewLC()
, use CleanupStack::PopAndDestroy()
to
destroy the object when its use is complete.
static CExample* CExample::NewLC() { CExample* self = new (ELeave) CExample(); CleanupStack::PushL(self); self->ConstructL(); return self; }
void doExampleL() { // allocate and push to cleanup stack - leave if failed CExample* myExample = CExample::NewLC(); // do something that might leave myExample->DoSomethingL(); // pop from cleanup stack and destroy CleanupStack::PopAndDestroy(); }