From 5de62bbe4dddc64895ddb17c4eb3572c3c9be248 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 19 Feb 2018 19:53:45 -0500 Subject: 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. --- source/slang/ir.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'source/slang/ir.cpp') diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 8667a67bd..65f792577 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -2648,6 +2648,12 @@ namespace Slang #endif } + void IRValue::dispose() + { + IRObject::dispose(); + type = decltype(type)(); + } + // Insert this instruction into the same basic block // as `other`, right before it. void IRInst::insertBefore(IRInst* other) @@ -4739,9 +4745,9 @@ namespace Slang if( !module ) { module = builder->createModule(); - sharedBuilder->module = module; } + sharedBuilder->module = module; sharedContext->module = module; sharedContext->originalModule = originalModule; sharedContext->target = target; @@ -4777,6 +4783,12 @@ namespace Slang IRSharedSpecContext* getSharedContext() { return &sharedContextStorage; } IRSpecContext* getContext() { return &contextStorage; } + ~IRSpecializationState() + { + newProgramLayout = nullptr; + contextStorage = IRSpecContext(); + sharedContextStorage = IRSharedSpecContext(); + } }; IRSpecializationState* createIRSpecializationState( @@ -4816,7 +4828,6 @@ namespace Slang auto context = state->getContext(); context->shared = sharedContext; context->builder = &sharedContext->builderStorage; - // Create the GlobalGenericParamSubstitution for substituting global generic types // into user-provided type arguments auto globalParamSubst = createGlobalGenericParamSubstitution(entryPointRequest, programLayout, context, originalIRModule); -- cgit v1.2.3