fix(core): Properly release and reclaim memory when stopping emulation #90
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/memory-allocation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This implements a more aggressive memory reclamation strategy when stopping emulation to prevent memory bloat and leaks. The entire purpose is to, instead of waiting for the Operating System to hitch & try to fix the issue itself with trying to reallocate RAM around, we free it immediately after the emulation stops, allowing users to have longer playtimes, and less worry about out-of-memory killers.
I've added a memory audit to ShutdownMainProcess that tracks the process RSS before and after shutdown. To actually give memory back to the OS, we now use MADV_DONTNEED (Linux) and MEM_RESET (Windows) on the device memory buffer, along with calling malloc_trim on Linux.
The Vulkan rasterizer now explicitly nukes its memory allocations, staging pools, and runtimes during destruction. This ensures all VkBuffer and VkImage handles are gone before the underlying memory slabs are freed.
Other changes:
Fixed a double-free crash in HostMemory by letting the unique_ptr handle cleanup automatically.
Reorganized the shutdown sequence to reset major systems (GPU, FS controller, etc.) before destroying the ServiceManager.
Updated Initialize and ReinitializeIfNecessary to handle memory layout changes and avoid redundant allocations.