What happens when CleanupStack::PushL() leaves?

Login to reply to this topic.
Thu, 2008-03-20 05:25
Joined: 2007-09-03
Forum posts: 25

Suppose I have done something line

CSomeClass* obj = new (ELeave) CSomeClass;
CleanupStack::PushL(obj);
.
.
.

Now, if CleanupStack::PushL(obj); leaves, how will the memory held by obj be deallocated?


Thu, 2008-03-20 08:08
Joined: 2003-09-29
Forum posts: 32
Re: What happens when CleanupStack::PushL() leaves?

Cleanupstack works so that there is always space for at least one more item. This means that in your example, first the obj will be put to a free slot in the stack and after that, if necessary, more memory will be allocated for the stack. So, it is possible that the memory allocation fails, but at that point, the pushed object is already in the stack.


Jari

Thu, 2008-03-20 09:03
Joined: 2007-09-15
Forum posts: 61
Re: What happens when CleanupStack::PushL() leaves?

Right. The cleanupStack is designed in such a way that whenever u allocate the pointer to an object on to the CleanupStack it will be added and additional space will be reserved for the next stack frame. So whenever the CleanupStack::PushL() leaves the pointer pushed is assured to have got its place. Only after this is the next check made abt the memory requirement. In case the next PushL() leaves, the stack is unwinded and the developer has nothing to do in that.

  • Login to reply to this topic.