Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline Matasx  
#1 Posted : Sunday, April 6, 2014 1:40:33 PM(UTC)
Matasx

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?

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline ollimorp  
#2 Posted : Tuesday, April 8, 2014 9:08:13 PM(UTC)
ollimorp

Joined: 7/22/2013(UTC)
Posts: 13

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Originally Posted by: Matasx Go to Quoted Post

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
Offline Benjamin  
#3 Posted : Wednesday, April 9, 2014 3:47:44 PM(UTC)
Benjamin

Medals: Admin

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.
Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
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.

Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.052 seconds.