It all has to do with the way you implement NewLC and NewL, but the STANDARD difference between NewLC and NewL is whether or not you have to CleanupStack->pop the object created.
Let's first start with the typical implementation of NewL and NewLC
static CObject* newL();
CObject* CObject::NewL() {
----CObject* self = NewLC();
----CleanupStack::Pop(self);
----return self;
}
static CObject* newLC();
CObject* CObject::NewLC() {
----CObject* self = new (ELeave)CObject();
----CleanupStack::PushL(self);
----self->Construct();
----return self;
}
As such, you would instantiate a CObject by using either of the following:
CObject* obj = CObject::NewL();
or
CObject* obj = CObject::NewLC();
// do something with obj that may require cleanup ie. cptrArray->AppendL(obj);
CleanupStack::Pop(obj);
If you do not pop the object, the stack will be messed up and you'll have a very difficult time figuring out why that is.
No comments:
Post a Comment