-
Notifications
You must be signed in to change notification settings - Fork 362
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
Release null objects from MemoryPoolBase #446
base: master
Are you sure you want to change the base?
Conversation
…estroy(entry). When the MemoryPool returns a value, which has been destroyed, this will cause problems. This is in problematic for MonoMemoryPool which can hold references to objects in a scene which is unloaded. I've added a minor addition to MemoryPoolBase which will release items which are null. It now pops items until it finds one which is not null and expands the pool whenever all items are popped (e.g. all items are destroyed because they belonged to an unloaded scene)
If that happens isn't that a mistake? Like shouldn't the fix be to not delete objects that have been added to the pool instead of fixing it inside the memory pool class? |
@svermeulen this usually is a problem in indirect scenarios where Unity does destroy the object and not the user via However - at least I believe so - it would be very difficult to keep all memory pools clean when you unload a scene. If there is e.g. a class In other scenarios I guess it should be really the best way to keep the pool clean in the first place, e.g. spawn, delete and never despawn deleted object. |
You're saying that you might want to continue using the memory pool when the scene changes? So it is bound in the project context? |
@svermeulen ProjectContext anmd/or a SceneContext of a scene in multi-scene (additive loading, scene parenting) scenarios which is not unloaded. |
In that case though, shouldn't the inactive pooled objects already be placed in the same scene where the pool is bounded? I don't understand why they are being deleted. One thing that does occur to me is that the old version of MonoMemoryPool was not resetting the parent automatically during despawn (but it is now in zenject 6), could that be related? |
@svermeulen Yes it should be and that could have been the problem bacck then. I will investigate and report later. Might take me a few weeks, just give me 2-3 weeks before we close this. |
Sure no problem |
In Unity MemoryPool entries can become null through calls to Object.Destroy(entry).
When the MemoryPool returns a value, which has been destroyed, this will cause problems. This is in particular problematic for MonoMemoryPool which can hold references to objects in a scene which is unloaded. I've added a minor addition to MemoryPoolBase which will release items which are null. It now pops items until it finds one which is not null and expands the pool whenever the last item had been popped (e.g. all items are destroyed because they belonged to an unloaded scene)