summaryrefslogtreecommitdiffstats
path: root/source/core/smart-pointer.h
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2018-02-20 23:55:51 -0500
committerGitHub <noreply@github.com>2018-02-20 23:55:51 -0500
commit01c4134d33cea3a4f98fad9248584278fd4bc452 (patch)
tree8ca6b0f7e844fbf56cb1991284aff3ebbcc8aa89 /source/core/smart-pointer.h
parent51cdcad24b5271ac8c0f816174c6a760e264ed9e (diff)
parent4cf46e5c8b2af8a4ea4db15cd402aae4145a614c (diff)
Merge pull request #417 from csyonghe/leakfix
Fix IR memory leaks.
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;