Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



How to implement and use 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();
 }