I'm building a level management system, which uses the ResourceInteractiveLoader
to load a level in background.
I have some issue with the memory management, that it seems C# does not allow free specific memory like delete
and free()
in C++, and all memory will be handled with GC after unused for a certain elapse, but I want the ResourceInteractiveLoader
object to be freed on my order, is it possible?
Asked
Active
Viewed 49 times
0

Qian2501
- 83
- 6
-
Did you take a look at the GarbageCollector(GC) class, yet? It allows you to force a garbage collection. https://learn.microsoft.com/en-us/dotnet/api/system.gc.collect?view=net-6.0 But keep in mind, that this will bring new performance problems, so only use it, while the player will not notice it. See https://stackoverflow.com/questions/478167/when-is-it-acceptable-to-call-gc-collect – Bugfish Oct 18 '22 at 07:05
-
@Bugfish yes, and that seems not actually a memory free, it only says “do GC now”, but the memory may not meets the criteria for collection – Qian2501 Oct 19 '22 at 03:06
-
As I see it ResourceInteractiveLoader implements the IDisposable Interface https://paulloz.github.io/godot-csharp-api/3.4/Godot.ResourceInteractiveLoader.html So you can use loader.Dispose() to explicitly release the resources. https://learn.microsoft.com/en-us/dotnet/api/system.idisposable?view=net-7.0 – Bugfish Oct 19 '22 at 10:18
-
@Bugfish oh, thanks, I‘ll try this out. This seems promising. – Qian2501 Oct 19 '22 at 11:08
-
Let me know, if it does the trick! Will formulate an answer, if it proofs helpful. – Bugfish Oct 19 '22 at 13:59
1 Answers
1
The ResourceInteractiveLoader implements the IDisposable Interface(https://learn.microsoft.com/en-us/dotnet/api/system.idisposable?view=net-7.0), which allows you to dispose the loader to explicity release the resources, when you don't need them anymore by calling:
loader.Dispose()

Bugfish
- 725
- 5
- 14