895 void CWsTop::SetCheckHeapOnDisconnectMode(TWsCheckHeapOnDisconnectMode aCheckHeapOnDisconnectMode) |
895 void CWsTop::SetCheckHeapOnDisconnectMode(TWsCheckHeapOnDisconnectMode aCheckHeapOnDisconnectMode) |
896 { |
896 { |
897 iHeapCheckMode=aCheckHeapOnDisconnectMode; |
897 iHeapCheckMode=aCheckHeapOnDisconnectMode; |
898 } |
898 } |
899 |
899 |
900 static void ReportAllCurrentLevelLeaks() |
|
901 { |
|
902 class RHeapWalk: public RHeap |
|
903 { |
|
904 public: |
|
905 static void WalkCheckCell(TAny* aPtr, TCellType aType, TAny* aCell, TInt aLen) |
|
906 { |
|
907 RHeapWalk* heap=(RHeapWalk*)aPtr; |
|
908 (void)aCell; |
|
909 switch(aType) |
|
910 { |
|
911 case EGoodAllocatedCell: |
|
912 if ( ((SDebugCell*)aCell)->nestingLevel == heap->iNestingLevel ) |
|
913 { |
|
914 RDebug::Printf("Leaked heap cell: level %i, serial %i @ %08x : len=%d", |
|
915 heap->iNestingLevel, ((SDebugCell*)aCell)->allocCount, aCell, aLen); |
|
916 } |
|
917 break; |
|
918 } |
|
919 } |
|
920 }; |
|
921 |
|
922 User::Heap().DebugFunction(RHeap::EWalk, (TAny*)RHeapWalk::WalkCheckCell, &User::Heap()); |
|
923 } |
|
924 |
|
925 TBool CWsTop::NeedsHeapCheckAndRestart(TInt aStartHeapCount) |
900 TBool CWsTop::NeedsHeapCheckAndRestart(TInt aStartHeapCount) |
926 { |
901 { |
927 if (!iDoHeapCheckAndRestart) |
902 if (!iDoHeapCheckAndRestart) |
928 return(EFalse); |
903 return(EFalse); |
929 iDoHeapCheckAndRestart=EFalse; |
904 iDoHeapCheckAndRestart=EFalse; |
930 iCheckHeapResult=User::Heap().Count()-aStartHeapCount; |
905 iCheckHeapResult=User::Heap().Count()-aStartHeapCount; |
931 if(iCheckHeapResult > 0) |
906 if(iCheckHeapResult > 0) |
932 { |
907 { |
933 const TUint32 orphanedCell = User::Heap().__DbgMarkEnd(aStartHeapCount); |
908 const TUint32 orphanedCell = User::Heap().__DbgMarkEnd(aStartHeapCount); |
934 RDebug::Printf("Memory leak detected in wserv. First orphaned cell: 0x%8x", orphanedCell); |
909 RDebug::Printf("Memory leak detected in wserv. First orphaned cell: 0x%8x", orphanedCell); |
935 ReportAllCurrentLevelLeaks(); |
|
936 } |
910 } |
937 return(ETrue); |
911 return(ETrue); |
938 } |
912 } |
939 |
913 |
940 TInt CWsTop::FetchCheckHeapResult() |
914 TInt CWsTop::FetchCheckHeapResult() |