Fixed minor memory leaks
authorrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 31 Jul 2012 19:23:02 +0000 (19:23 +0000)
committerrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 31 Jul 2012 19:23:02 +0000 (19:23 +0000)
http://codereview.appspot.com/6453066/

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

samplecode/SampleDecode.cpp
src/gpu/gl/debug/GrDebugGL.cpp
src/gpu/gl/debug/GrDebugGL.h
src/gpu/gl/debug/GrGLCreateDebugInterface.cpp

index 9188257..fa2b727 100644 (file)
@@ -27,7 +27,7 @@ class DecodeView : public SkView {
 public:
     SkBitmap fBitmap[SK_ARRAY_COUNT(gRec)];
 
-       DecodeView() {
+    DecodeView() {
         SkFILEStream stream("/skimages/index.png");
         SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
         if (codec) {
@@ -37,6 +37,7 @@ public:
                 codec->decode(&stream, &fBitmap[i], gRec[i].fPrefConfig,
                               SkImageDecoder::kDecodePixels_Mode);
             }
+            SkDELETE(codec);
         }
     }
     
index c4cfe89..6570039 100644 (file)
@@ -16,7 +16,8 @@
 #include "GrTextureUnitObj.h"
 
 
-GrDebugGL GrDebugGL::Obj;
+GrDebugGL* GrDebugGL::gObj = NULL;
+int GrDebugGL::gStaticRefCount = 0;
 GrDebugGL::Create GrDebugGL::gFactoryFunc[kObjTypeCount] = {
     GrTextureObj::createGrTextureObj,
     GrBufferObj::createGrBufferObj,
@@ -40,7 +41,9 @@ GrDebugGL::GrDebugGL()
     , fTexture(NULL) {
 
     for (int i = 0; i < kDefaultMaxTextureUnits; ++i) {
-        fTextureUnits[i] = GR_CREATE(GrTextureUnitObj, GrDebugGL::kTextureUnit_ObjTypes);
+
+        fTextureUnits[i] = reinterpret_cast<GrTextureUnitObj *>(
+                            createObj(GrDebugGL::kTextureUnit_ObjTypes));
         fTextureUnits[i]->ref();
 
         fTextureUnits[i]->setNumber(i);
index 4e714ee..d6697fd 100644 (file)
@@ -84,13 +84,31 @@ public:
     GrGLint getUnPackRowLength() const { return fUnPackRowLength; }
 
     static GrDebugGL *getInstance() {
-//        static GrDebugGL Obj;
+        // someone should admit to actually using this class
+        GrAssert(0 < gStaticRefCount);
 
-        return &Obj;
+        if (NULL == gObj) {
+            gObj = SkNEW(GrDebugGL);
+        }
+
+        return gObj;
     }
 
     void report() const;
 
+    static void staticRef() {
+        gStaticRefCount++;
+    }
+
+    static void staticUnRef() {
+        GrAssert(gStaticRefCount > 0);
+        gStaticRefCount--;
+        if (0 == gStaticRefCount) {
+            SkDELETE(gObj);
+            gObj = NULL;
+        }
+    }
+
 protected:
 
 private:
@@ -113,7 +131,8 @@ private:
 
     static Create gFactoryFunc[kObjTypeCount];
 
-    static GrDebugGL Obj;
+    static GrDebugGL* gObj;
+    static int gStaticRefCount;
 
     // global store of all objects
     SkTArray<GrFakeRefObj *> fObjects;
index 22f32dc..3f58cc6 100644 (file)
@@ -1280,6 +1280,11 @@ public:
 
     GrDebugGLInterface()
         : fWrapped(NULL) {
+        GrDebugGL::staticRef();
+    }
+
+    virtual ~GrDebugGLInterface() {
+        GrDebugGL::staticUnRef();
     }
 
     void setWrapped(GrGLInterface *interface) {