Forum Nokia Tools and Technologies - Nokia Developer - 你的灵感,我 ...
Forum Nokia Tools and Technologies - Nokia Developer - 你的灵感,我 ...
Forum Nokia Tools and Technologies - Nokia Developer - 你的灵感,我 ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Why a cleanup stack is needed?<br />
• If a function leaves, control returns immediately to the TRAP harness<br />
within which it was called, generally the default TRAP harness inside<br />
the thread’s Active Scheduler. This means that any automatic variables<br />
within functions called inside the TRAP harness are destroyed.<br />
However, a problem arises if any of these automatic variables are<br />
pointers to objects allocated on the heap. When the leave occurs <strong>and</strong><br />
the pointer is destroyed, the object it pointed to is orphaned <strong>and</strong> a<br />
memory leak occurs<br />
TRAPD( error,doExampleL() );<br />
void doExampleL()<br />
{<br />
CSomeObject* myObject1 = new (ELeave) CSomeObject;<br />
CSomeObject* myObject2 = new (ELeave) CSomeObject;<br />
delete myObject1; // Wrong<br />
delete myObject2;<br />
}<br />
Where enum TLeave {ELeave} is defined in “e32std.h”