SFML community forums

Bindings - other languages => DotNet => Topic started by: P@u1 on September 07, 2011, 10:26:36 am

Title: Is it important to Dispose SFML objects?
Post by: P@u1 on September 07, 2011, 10:26:36 am
Hi everyone,

I wondered if it is important to call Dispose on every single sfml-object or not and what happens if I dont do it.

It probably means that the destructors are not called, but what does this mean?

Just that we loose some memory, or are there also resources which get lost until a computer restart?

I know that the destructor also disposes the objects, but that only happens when the garbage collector collects these objects.
I read that C# does usually not run the garbage collector on shutdown.
Title: Is it important to Dispose SFML objects?
Post by: omeg on September 07, 2011, 11:27:34 am
You can leak OS handles (for fonts, bitmaps etc) so if your application runs for a long time, it can become a problem. It will eventually all be freed in the end, but you should Dispose() everything after you're done with it - this will improve your code's performance and lessen memory usage. I actually blogged about this very issue recently, so if you are interested - Optimizing Garbage Collector performance in your .NET application (http://omeg.pl/blog/2011/08/optimizing-garbage-collector-performance-in-your-net-application/).
Title: Is it important to Dispose SFML objects?
Post by: P@u1 on September 21, 2011, 10:14:18 am
So far I didn't put Dispose() calls in.
When I end the application quite often an AccessViolationException in SFML code appears.
Why does this happen? Looks like a bug.

Edit: Maybe I will add Dispose() calls and try if it still does happen.
Title: Is it important to Dispose SFML objects?
Post by: P@u1 on September 22, 2011, 12:52:59 pm
I now added Dispose calls and it doesen't crash anymore.
But why did it crash when I didn't call Dispose()?
Is this some bug in the destructor code?