Objects with a link to "Any State" do not free memory even if they disappear

I am creating a game that destroys large numbers of enemies, similar to a bullet hell shooter.

During testing, I noticed that memory usage gradually increases.

image

Upon investigating the cause, I found that if there is a link from the enemy’s VS “Any State”, memory is not released even after the enemy is destroyed.

By monitoring the object count in Godot’s monitor, I confirmed that the count increases when the “Any State” link is present, but remains unchanged when it is absent. The link condition can be anything, such as “variable change” or “contact with attack hitbox,” and it seems to not matter whether the transition occurs during gameplay or not. Additionally, it appears that memory is not released even when transitioning to another game scene.

Note that the issue is reproducible in version 1.2.6, but I first noticed it in a previous version, so I do not believe the “Any State” addition feature in 1.2.6 is related.

I have attached the project used for testing.

memorytest.zip (24.3 KB)

Well this is sure interesting. I tried also deleting the Any State node entirely and there was still slight increase. I wonder if it’s because of the ever-increasing reference list of GameObjects in the case of Restore condition. I don’t know ultimately, but I did forward this to the developers so they can better investigate the cause.

Thanks for brining it to our attention and for the minimal project!

1 Like

Thank you for the report.

We confirmed that memory increases even without the “Any State” link.
Since objects and resources are not increasing, it is likely that some data, such as a list, is not being released.

This seems related to the issue: when particles are emitted, the object count does not fully return to normal even after they disappear.
For example, if you create a stage that simply emits a large number of particles and repeatedly perform “emit particles → reset” (whether you wait for them to disappear or not), the object count on the monitor increases in a stepwise manner.

1 Like

@tamaki I can confirm they found and fixed the issue. I’m guessing will make next patch!

@udon365 First thought would be are you using a duration or unlimited time? If you are using unlimited time I could suspect the object count would increase. If you don’t know the exact duration you could give it a large amount so that eventually it frees from the runtime.

image

1 Like

We have fixed the AnyState issue in today’s release, version 1.2.7!

1 Like

Thank you for your response.

We have confirmed that memory and object usage do not increase in version 1.2.7.

I apologize. It seems the issue with the particle object count not fully resetting is unrelated to the AnyState memory leak problem discussed in this thread…
Just to clarify, I have only set the “Duration” and have not checked “Persist Display Time.”
Regarding this issue, it might be caused by my use of sub-emitters with “Forward+”.

1 Like