summaryrefslogtreecommitdiffstats
path: root/source/core/smart-pointer.h
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2018-02-19 19:53:45 -0500
committerYong He <yonghe@outlook.com>2018-02-19 19:53:45 -0500
commit5de62bbe4dddc64895ddb17c4eb3572c3c9be248 (patch)
treed12fd2a9bad9a632430e1262de8f7e7da388bffa /source/core/smart-pointer.h
parentff8adf7b45121aada0b4f4403b0f45a6e2dfe475 (diff)
more to fixing memory leaks
1. reorder destruction order of several key classes to avoid using deleted IR objects when destroying Types 2. remove Session::canonicalTypes and make each Type own a RefPtr to the canonicalType, to allow types to be destroyed along with each IRModule it belongs to.
Diffstat (limited to 'source/core/smart-pointer.h')
-rw-r--r--source/core/smart-pointer.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/source/core/smart-pointer.h b/source/core/smart-pointer.h
index 17d6caaa4..bc1683a5b 100644
--- a/source/core/smart-pointer.h
+++ b/source/core/smart-pointer.h
@@ -35,6 +35,11 @@ namespace Slang
referenceCount++;
}
+ void decreaseReference()
+ {
+ --referenceCount;
+ }
+
void releaseReference()
{
SLANG_ASSERT(referenceCount != 0);
@@ -192,6 +197,15 @@ namespace Slang
return pointer;
}
+ T* detach()
+ {
+ if (pointer)
+ dynamic_cast<RefObject*>(pointer)->decreaseReference();
+ auto rs = pointer;
+ pointer = nullptr;
+ return rs;
+ }
+
private:
T* pointer;