From ff8adf7b45121aada0b4f4403b0f45a6e2dfe475 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 19 Feb 2018 13:00:51 -0500 Subject: Fix IR memory leaks. 1, make IRModule class own a memory pool for all IR object allocations 2. For now, we allow IR objects to own other (externally) heap allocated objects, such as String, List and RefPtrs by tracking all IR objects that has been allocated for the IRModule in a list named `IRModule::irObjectsToFree`. and call destructor for all these objects upon the destruction of the IRModule. In the long term, we should eliminate the use of all these externally allocated types in IR system and get rid of this tracking and explicit destructor calls. 3. remove non-generic `createValueImpl` functions and retain only generic versions in IRBulider so we can properly call the constructor of the IR types to set up virtual tables correctly for destructor dispatching. 4. add `MemoryPool` class for allocation of the IR objects. 5. Make sure we are disposing IRSpecContexts when we are done with the specialized IR module. 6. Add `_CrtDumpMemoryLeaks()` calls to check memory leaks upon destruction of a Slang session. If we are to support multiple sessions at a time, this call should probably be replaced with the more advanced MemoryState versions of the memory leak checker. --- source/slang/memory_pool.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 source/slang/memory_pool.h (limited to 'source/slang/memory_pool.h') diff --git a/source/slang/memory_pool.h b/source/slang/memory_pool.h new file mode 100644 index 000000000..ee3ee1aa3 --- /dev/null +++ b/source/slang/memory_pool.h @@ -0,0 +1,19 @@ +#ifndef SLANG_MEMORY_POOL_H +#define SLANG_MEMORY_POOL_H + +#include "../core/basic.h" + +namespace Slang +{ + struct MemoryPoolSegment; + + struct MemoryPool : public RefObject + { + MemoryPoolSegment* curSegment = nullptr; + ~MemoryPool(); + void* alloc(size_t size); + void* allocZero(size_t size); + }; +} + +#endif \ No newline at end of file -- cgit v1.2.3