Mar-29-2018, 02:01 AM
Just ran into a case where the garbage collector is absolutely not doing what I need it to do.
Context: I'm creating a game hub from which users can enter a number of different mini games. The mini games may have their own resources which load when they are started up, but they need to release this memory when you exit back to the menu. My initial intuition was to kill all links to these resources so when the specific game instance goes out of scope the gc should reclaim the memory. This has unfortunately proved problematic. The resources do not get cleaned up quickly, and in fact if I exit and restart the mini game from the hub I can push the memory usage as high as I want... which is not good.
I have now added an explicit
Context: I'm creating a game hub from which users can enter a number of different mini games. The mini games may have their own resources which load when they are started up, but they need to release this memory when you exit back to the menu. My initial intuition was to kill all links to these resources so when the specific game instance goes out of scope the gc should reclaim the memory. This has unfortunately proved problematic. The resources do not get cleaned up quickly, and in fact if I exit and restart the mini game from the hub I can push the memory usage as high as I want... which is not good.
I have now added an explicit
gc.collect
call after a state flip and this gets the job done, but I do wonder why the automatic gc is being so unreliable. I would rather not have to resort to this.