GodotAsyncLoader icon indicating copy to clipboard operation
GodotAsyncLoader copied to clipboard

Add a way to remove scenes from cache?

Open d-eisenga opened this issue 3 years ago • 7 comments

I was looking at SceneLoader.gd, specifically the _get_cached_scene function, and it looks like scenes never get removed from the _scenes cache. It looks like the cache just going to grow and grow while the game runs, using ever more memory. Some way to remove scenes from the cache will probably be needed for larger games.

d-eisenga avatar Jun 20 '22 17:06 d-eisenga

I'll have to look into this more. I'm pretty sure that PackedScene is reference counted, and will get auto freed when there is nothing else using it.

workhorsy avatar Jun 21 '22 07:06 workhorsy

I'd assume if it's a value in a dictionary that would be considered a reference, but I admit I don't know much about Godot memory management.

d-eisenga avatar Jun 21 '22 16:06 d-eisenga

For reference see ResourceCache: https://github.com/godotengine/godot/blob/3.5/core/io/resource_loader.cpp https://github.com/godotengine/godot/blob/3.5/core/io/resource_loader.h

https://docs.godotengine.org/en/3.5/tutorials/scripting/resources.html#freeing-resources

workhorsy avatar Aug 29 '22 01:08 workhorsy

Is this problem solved? Can you write if it is solved?

unicornlox avatar Jan 19 '23 06:01 unicornlox

Hey @mrParabol . Unfortunately I ran into a design flaws with the current code. I'm working on a partial re write that should solve these problems. I've just been super busy with real world stuff. So I haven't had as much time to work on improving things. Hopefully I will have more time soon.

workhorsy avatar Jan 20 '23 17:01 workhorsy

hello @workhorsy Thank you for your answer. I understand you. In fact, if you explain why the added scene is not deleted or stayed in Cache, I can continue my way. I delete the added scene from the stage tree, but when I switch to different stage, the scene I deleted is added again. I am making a game and I used your plug -in in my game, but I cannot release my game with this problem. I used this plug -in in many different places, and I can't go back. If you can give a clue to prevent my efforts from going to waste, I will be grateful to you.

unicornlox avatar Jan 28 '23 04:01 unicornlox

Hi @mrParabol . It sounds like you are talking about 2 different bugs. The cache only loads and stores a PackedScene. Those PackedScene resources are then cached. Instances of those PackedScenes are not cached. The instances are then added to the scene tree.

I think this may be a different bug. Can you show the code where you are using the plugin to add and remove to the scene tree?

Thanks

workhorsy avatar Jan 28 '23 18:01 workhorsy