Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Is it important to Dispose SFML objects?  (Read 2780 times)

0 Members and 1 Guest are viewing this topic.

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
Is it important to Dispose SFML objects?
« 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.

omeg

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • http://omeg.pl/
Is it important to Dispose SFML objects?
« Reply #1 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.

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
Is it important to Dispose SFML objects?
« Reply #2 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.

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
Is it important to Dispose SFML objects?
« Reply #3 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?

 

anything