Symbian
Symbian OS Library

FAQ-0539 What might be the cause of a seemingly wrong "alloc heaven" panic from the __UHEAP macros?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: Base
Created: 11/09/2000 Modified: 09/11/2002
Number: FAQ-0539
Platform: Not Applicable

Question:
I'm using the __UHEAP_MARK and __UHEAP_MARKEND macros around part of my code but it always panics even though I'm clearly not leaking any memory.

Answer:
One possible cause of this could be the cleanup stack expanding as part of normal function processing. The standard solution to this is to write:

#ifdef _DEBUG
const TInt KMaxCleanupFrames=10; // usually more than enough
for (TInt i=0; i CleanupStack::Pop(KMaxCleanupFrames);
#endif

close to the start of your processing which will serve to preallocate a reasonable number of cleanup stack frames. These steps should be made conditional for debug builds only because the __UHEAP macros do not apply under release builds.

Note: It would be very rare to have to allocate more than 10 frames. Most objects exist on the CleanupStack for a short time only, usually during second-phase construction, hence there are not many situations where more than 10 would be in place at once.