diff -r 79859ed3eea9 -r 919f36ff910f widgets/widgetapp/src/WidgetUiApp.cpp --- a/widgets/widgetapp/src/WidgetUiApp.cpp Tue Aug 31 16:17:46 2010 +0300 +++ b/widgets/widgetapp/src/WidgetUiApp.cpp Wed Sep 01 12:28:30 2010 +0100 @@ -15,12 +15,12 @@ * */ - -#include "WidgetUiApp.h" -#include "WidgetUiDocument.h" -#include "MemoryManager.h" -#include "widgetappdefs.rh" -#include +#include "WidgetUiApp.h" +#include "WidgetUiDocument.h" +#include +#include "widgetappdefs.rh" +#include +#include // EXTERNAL DATA STRUCTURES @@ -88,18 +88,48 @@ } // ----------------------------------------------------------------------------- +// SetupThreadHeap - Called for heap creation of thread in this process. +// This approach used to keep correct heap for pointers held in static data objects +// when they are destructed after E32Main() by OS. +// ----------------------------------------------------------------------------- +// +EXPORT_C TInt UserHeap::SetupThreadHeap(TBool aSubThread, SStdEpocThreadCreateInfo& aInfo) + { + TInt r = KErrNone; + if (!aInfo.iAllocator && aInfo.iHeapInitialSize>0) + { + // new heap required + RHeap* pH = NULL; + r = CreateThreadHeap(aInfo, pH); + if (r == KErrNone && !aSubThread) + { + // main thread - new allocator created and set as default heap + MemoryManager::CreateFastAllocator(); + } + } + else if (aInfo.iAllocator) + { + // sharing a heap + RAllocator* pA = aInfo.iAllocator; + pA->Open(); + User::SwitchAllocator(pA); + } + + return r; + } + + +// ----------------------------------------------------------------------------- // E32Main // // ----------------------------------------------------------------------------- // GLDEF_C TInt E32Main() { - RAllocator* oldAllocator = MemoryManager::SwitchToFastAllocator(); - __UHEAP_MARK; - TInt result = EikStart::RunApplication( NewApplication ); - __UHEAP_MARKEND; - MemoryManager::CloseFastAllocator(oldAllocator); - return result; + // initialize MemmoryManager + MemoryManager::InitFastAllocator(); + + return EikStart::RunApplication(NewApplication); } - + // End of File