Skip to content
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

Big memory leak when spawning too many Area2Ds #100600

Open
GustJc opened this issue Dec 19, 2024 · 1 comment
Open

Big memory leak when spawning too many Area2Ds #100600

GustJc opened this issue Dec 19, 2024 · 1 comment

Comments

@GustJc
Copy link
Contributor

GustJc commented Dec 19, 2024

Tested versions

  • Reproducible in: v4.3.stable.mono.official [77dcf97]

System information

Windows 10 - Vulkan(Foward+) - Nvidea 1070

Issue description

There seems to be a big memory leak when spawning too many Area2D's too fast.
This leak also happens when using JoltPhysics2D.
And maybe some other problems.

Here it is working normally, spawning moving bullets.
Because the FPS drops, it spawns slower and doesn't leak memory.
298 MB static memory after 1000 Area2D spawned.
And 132k collision pairs

non_leak_area2d.mp4

And here it is leaking memory.
When I try to spawn non-moving bullets.
It spawns them very fast. But the memory goes up very fast.
906 MB static memory after 1000 Area2D spawned.
And 500k collision pairs

leak_area2d.mp4

I've also tested the same with Node2D and Character2D but they work fine.
This only happens with Area2Ds


PS: Its strange that the FPS in the MRP tanks to 4 FPS so fast with only 500+ nodes too.
I was getting a stable 40 frames with 2k bullets on my other project.
I thought maybe it was because I was spawning them there with coroutines, but the performance on the MRP stays at 4 FPS even after it finishes spawning the 1k bullets.
So something else might be wrong.


As a side-note, when the memory-leak example finishes spawning my computer starts screeching.
Which I'm guessing is my old HDD asking for help.
This also rarely happens here when windows starts indexing or reading tons of small files.
Not sure this is related but a fun tidbit.

Steps to reproduce

MRP:

  • Run the MRP project
  • Look at the monitor tab static memory

Expected: NOT to increase so much. Expected around 200-300 MBs.
Result: static memory 900+Mbs

Non-MRP:

  • Spawn 5 Area2D's each frame

Expected: Normal static memory increase.
Result: static memory increase very fast.

Minimal reproduction project (MRP)

MRP_memory-leak-physics.zip

@Ferhunt
Copy link

Ferhunt commented Dec 20, 2024

I tested this project in a custom build of fafc073 and found the same memory usage of just over 900 MiB. Spawning moving nodes brought the frame rate down to 1 FPS and the engine reported lower memory usage of 253 MiB, though strangely limiting the FPS through the project settings to the same 1 FPS still consumes the full 907 MiB. The terminal output does not report a memory leak.

I tried spawning non-moving nodes and changing them to moving halfway through and at the end the engine reported a peak of 435 MiB which dropped to 378 as the moving nodes stopped overlapping with the stationary ones. What was strange was that the moment I toggled to spawning moving nodes memory usage dropped a little and then climbed at the slower pace until peaking, then dropping again as I mentioned. Spawning all nodes on the same frame used a little more memory, at 930 MiB.

Spawning the nodes at random positions from 0, 0 to 1920, 1080 lowers the memory usage dramatically to 141 Mib, and collision pairs to 15844, which leads me to believe that the memory used is taken up by the collisions and not a leak. I don't know if up to 907 MiB from 253 MiB is justified by just the collisions, but it doesn't seem too outlandish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants