-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResourceLoader
threaded loading causes memory leak
#89585
Comments
After further testing, I think the problem starts at 4.3.dev3. Can't reproduce it in 4.2.2.rc2 or 4.3.dev2. (I'm OP. Didn't notice I used an alt account when posting this issue.) |
Just to clarify, using extends Node2D
const PATH = 'res://white_1024.png'
const MAX_LOAD_COUNT = 2000
var load_count := 0
func _physics_process(__):
if load_count < MAX_LOAD_COUNT:
var test := ResourceLoader.load(PATH)
assert(ResourceLoader.has_cached(PATH) == true)
test = null
assert(ResourceLoader.has_cached(PATH) == false)
load_count += 1 The resulting memory usage graph is a straight line. It didn't budge at all. |
I just spent a day bisecting to the same commit: ae418f9 My voxel engine generates meshes at runtime very often in threads. It looks like an amount of memory similar to the size of a mesh is getting leaked every time I generate chunks. This lead to very bad memory consumption and eventually crashes. It doesn't reproduce with a minimal project that just creates meshes on the main thread with Regarding ae418f9, I had a brief look and one thing that strikes me is that before, there was a call to the destructor of CommandBase: cmd->~CommandBase(); //should be done, so erase the command But I can't find it anymore in the new version. |
Just tested this: @@ -374,10 +374,12 @@ class CommandQueueMT {
cmd->call();
if (sync_sem) {
sync_sem->sem.post(); // Release in case it needs sync/ret.
}
+ cmd->~CommandBase();
+ Which gets rid of the leak. It comes in total contradiction with |
@Zylann, that's very interesting. My assessment was indeed that the destructor is trivial and therefore I could avoid calling it. However, that was not the primary reason for removing the call, but something that gave me peace of mind in removing it, the main reason being how reentrancy was being handled. Now reentrancy is handled differently, it can be run, regardless trivial or not. I will add the fix in a PR I'm working on that adds more fixes to threaded servers. I was finding some leaks that may be tracked down to this same issue. I'm very curious as to why my rationale was wrong. I'll report when I know. |
Oh, of course. Although they are certainly hidden in the macro magic, derivatives of |
Confirmed on Linux. |
Tested versions
System information
Godot v4.3.dev5 - Windows 10.0.19045 - GLES3 (Compatibility) - Radeon RX 560X Series (Advanced Micro Devices, Inc.; 31.0.21910.5) - AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx (8 Threads)
Issue description
Using
ResourceLoader
's threaded loading mechanism causes memory leaks.Here is a short script which demonstrates it. It just loads a white texture repeatedly. Note how it doesn't hold any references to the loaded texture by the end of
_physics_process
.Steps to reproduce
MAX_LOAD_COUNT
is reached).Not sure if related, but notice how the texture memory usage didn't really change throughout.
Sample Run:
Minimal reproduction project (MRP)
resource_threaded_mem_leak_MRP.zip
The text was updated successfully, but these errors were encountered: