From 98e59450f1bd0f825e070a87db8e362cad34a2fa Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 25 May 2025 17:39:51 +0200 Subject: [PATCH] Add freeing managed assembly memory on reload/unload --- Source/Engine/Core/Memory/Allocation.cpp | 7 +++++-- Source/Engine/Scripting/ManagedCLR/MCore.cpp | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Core/Memory/Allocation.cpp b/Source/Engine/Core/Memory/Allocation.cpp index 87c9dbc63..59b3a8a7e 100644 --- a/Source/Engine/Core/Memory/Allocation.cpp +++ b/Source/Engine/Core/Memory/Allocation.cpp @@ -14,6 +14,9 @@ void ArenaAllocator::Free() Allocator::Free(page); page = next; } + + // Unlink + _first = nullptr; } void* ArenaAllocator::Allocate(uint64 size, uint64 alignment) @@ -31,14 +34,14 @@ void* ArenaAllocator::Allocate(uint64 size, uint64 alignment) page->Memory = Allocator::Allocate(pageSize); page->Next = _first; page->Offset = 0; - page->Size = pageSize; + page->Size = (uint32)pageSize; _first = page; } // Allocate within a page page->Offset = Math::AlignUp(page->Offset, (uint32)alignment); void* mem = (byte*)page->Memory + page->Offset; - page->Offset += size; + page->Offset += (uint32)size; return mem; } \ No newline at end of file diff --git a/Source/Engine/Scripting/ManagedCLR/MCore.cpp b/Source/Engine/Scripting/ManagedCLR/MCore.cpp index 4ded56b52..675e09ddf 100644 --- a/Source/Engine/Scripting/ManagedCLR/MCore.cpp +++ b/Source/Engine/Scripting/ManagedCLR/MCore.cpp @@ -143,6 +143,7 @@ void MAssembly::Unload(bool isReloading) #else _classes.ClearDelete(); #endif + Memory.Free(); Unloaded(this); }