Delta Engine
»
Support
»
Engine
»
Disposing objects
Joined: 8/30/2013(UTC) Posts: 43
Thanks: 11 times Was thanked: 1 time(s) in 1 post(s)
|
Hi. I'm using Dispose method to release objects from memory and I'm also setting pointer to null after disposing (so GC can collect the object, because there is no strron reference to it). But the memory seems only to grow (even after GC collect). Code:
this.MySprite.Dispose();
this.MySprite = null;
//GC.Collect - no memory released
It seems, that DE implementation of IDisposable interface only sets property IsActive to false and nothing else. Is it possible to fully release single DE object including all managed and unmanaged resources?
|
|
|
|
Joined: 7/22/2013(UTC) Posts: 13
Thanks: 1 times Was thanked: 2 time(s) in 2 post(s)
|
Originally Posted by: Matasx  It seems, that DE implementation of IDisposable interface only sets property IsActive to false and nothing else. Is it possible to fully release single DE object including all managed and unmanaged resources?
Hi. You´re right, but when remembering correctly, the EntitiesRunner sets the references to the entity to null, after IsActive have been set to false. If you have further references to this inactive entity, I think you have to null these too. Best regards
|
|
|
|
Medals:  Joined: 8/20/2011(UTC) Posts: 1,421 Location: Hannover
Thanks: 18 times Was thanked: 97 time(s) in 92 post(s)
|
An entity has nothing more to do than to become inactive. Setting IsActive to false will remove it from the EntitiesRunner and thus break all relationships. If the user holds on to the entity, it will still be around and can be made active again, but otherwise it is garbage collected and gone. You can obviously also override Dispose to dispose more data.
Keep in mind that ContentData disposing is not done by entities because content like images are shared and not owned by a single entity. If you dispose an image (which is of course possible at any time, if you want to manually free up some memory) the next user will automatically get a new one, so it works, but is not very efficient.
In a normal app or game disposing should not be an issue anyways, especially in your game loop you never want to dispose anything to avoid calling the Garbage Collector (not relevant on converted C++ code of course). In between scenes things should be loaded, initialized and disposed. This is how it was planed and we recently began ContentLoader refactoring to make this feature more apparent and easier to use: - Start Game, loads GhostWars scene content (logos, music, etc.) that are always around -- Load Scene GhostWars.MainMenu, which displays the main menu --- Load Scene GhostWars.Credits, which displays the credits screen with its own content -- Go back to Scene, all GhostWars.Credits content, entities, etc. are disposed --- Load Scene GhostWars.LevelSelection ---- Load Scene GhostWars.Level1 etc.
In each of these scenes all content is loaded at initialization time (with a loading screen if it takes too long (>1s), but in our examples it is very quick), then used in the entities, sometimes new entities might be created, but rarely, most of the things are created at initialization time. Then when switching to another scene we either keep all content (and deactivate all entities) if the new scene is nested, or we dispose it all and load the next scene. That system has been used in SoulCraft for many years (in a more manual way) and is very useful, easy to use and efficient.
|
|
|
|
Delta Engine
»
Support
»
Engine
»
Disposing objects
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.