javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/src/swtinstancecounts.cpp
branchRCL_3
changeset 19 04becd199f91
child 60 6c158198356e
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Nokia Corporation - S60 implementation
       
    10  *******************************************************************************/
       
    11 
       
    12 
       
    13 #if defined(__WINS__) && defined(_DEBUG)
       
    14 
       
    15 
       
    16 #include "swtinstancecounts.h"
       
    17 #include "swtdisplay.h" // needed for macro definitions
       
    18 
       
    19 
       
    20 // ======== LOCAL FUNCTIONS ========
       
    21 
       
    22 
       
    23 static void CheckLeak(TInt& aCount, TInt aCorrectCount=0)
       
    24 {
       
    25     // The reason for stopping here is that eSWT Display is being disposed
       
    26     // but not all the eSWT resources have been appropriately freed by
       
    27     // calling dispose(). This creates a memory leak. Step up the call stack
       
    28     // into CheckForLeaks() and you will see which type of object was leaked.
       
    29     // Likely reasons for this error are:
       
    30     // - The Java application not disposing its eSWT resources appropriately
       
    31     //   (e.g. Images, Fonts, GCs, Colors)
       
    32     // - eSWT widget not appropriately disposing another eSWT object it owns
       
    33     //   when being disposed itself
       
    34 #ifdef ESWT_NATIVE_UITHREAD_OWN_HEAP
       
    35     ASSERT(aCount == aCorrectCount);
       
    36 #endif // ESWT_NATIVE_UITHREAD_OWN_HEAP
       
    37 
       
    38     if (aCount != aCorrectCount)
       
    39     {
       
    40         aCount = aCorrectCount;
       
    41     }
       
    42 }
       
    43 
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 
       
    48 void TSwtInstanceCounts::CheckForLeaks()
       
    49 {
       
    50     CheckLeak(iColor);
       
    51     CheckLeak(iFont);
       
    52     CheckLeak(iGc);
       
    53     CheckLeak(iImage);
       
    54     CheckLeak(iScrollBar);
       
    55     CheckLeak(iMenu);
       
    56     CheckLeak(iMenuItem);
       
    57     CheckLeak(iCommand);
       
    58     CheckLeak(iClipboard);
       
    59     CheckLeak(iTableColumn);
       
    60     CheckLeak(iTableItem);
       
    61     CheckLeak(iTreeItem);
       
    62 
       
    63     // Controls deserve a special treatment as we don't know precisely which has been disposed
       
    64     const TInt ctrlSum = iButton         + iCanvas            + iCaptionedControl  + iCombo
       
    65                          + iComposite      + iConstrainedText   + iDateEditor        + iDecorations
       
    66                          + iHyperLink      + iLabel             + iList              + iListBox
       
    67                          + iListView       + iMultiPagePager    + iMultiPageTabGroup + iMultiPageDialog
       
    68                          + iProgressBar    + iShell             + iSlider            + iSortedList
       
    69                          + iText           + iTextExtension     + iTable             + iTree
       
    70                          + iBrowser        + iMobileShell       + iDCControl;
       
    71     CheckLeak(iDisposedControls, ctrlSum);
       
    72 }
       
    73 
       
    74 
       
    75 #endif // defined(__WINS__) && defined(_DEBUG)