Altered SkInstCnt to print out atexit
authorrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 27 Jun 2012 19:52:20 +0000 (19:52 +0000)
committerrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 27 Jun 2012 19:52:20 +0000 (19:52 +0000)
http://codereview.appspot.com/6348043/

git-svn-id: http://skia.googlecode.com/svn/trunk@4377 2bbb7eff-a529-9590-31e7-b0007b416f81

gm/gmmain.cpp
include/core/SkInstCnt.h

index b34a4424e69903aeddc51eaa0b7b69be8052b3eb..8483dae2454bc3b8cdaf984ce90932c06cc7aa23 100644 (file)
@@ -1091,10 +1091,5 @@ int main(int argc, char * const argv[]) {
     delete grFactory;
     SkGraphics::Term();
 
-#ifdef SK_DEBUG
-    SkRefCnt::CheckInstanceCount();
-    SkWStream::CheckInstanceCount();
-#endif
-
     return (0 == testsFailed) ? 0 : -1;
 }
index 18ea9bb75a013e8c440476fb02fb4f42fcb12189..9ec18d5176fe50dc97d9b9a07780b0cc099d63e1 100644 (file)
  * CheckInstanceCount methods should be made
  */
 #ifdef SK_ENABLE_INST_COUNT
+#include <stdlib.h>
 #include "SkTArray.h"
 
 extern bool gPrintInstCount;
 
+// The non-root classes just register themselves with their parent
 #define SK_DECLARE_INST_COUNT(className)                                    \
     SK_DECLARE_INST_COUNT_INTERNAL(className,                               \
                                 INHERITED::AddInstChild(CheckInstanceCount);)
 
+// The root classes registers a function to print out the memory stats when
+// the app ends
 #define SK_DECLARE_INST_COUNT_ROOT(className)                               \
-    SK_DECLARE_INST_COUNT_INTERNAL(className, ;)
+    SK_DECLARE_INST_COUNT_INTERNAL(className, atexit(exitPrint);)
 
 #define SK_DECLARE_INST_COUNT_INTERNAL(className, initStep)                 \
     class SkInstanceCountHelper {                                           \
@@ -59,6 +63,10 @@ extern bool gPrintInstCount;
         return SkInstanceCountHelper::gInstanceCount;                       \
     }                                                                       \
                                                                             \
+    static void exitPrint() {                                               \
+        CheckInstanceCount();                                               \
+    }                                                                       \
+                                                                            \
     static int CheckInstanceCount(int level = 0) {                          \
         if (gPrintInstCount && 0 != SkInstanceCountHelper::gInstanceCount) {\
             SkDebugf("%*c Leaked %s: %d\n",                                 \