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

Author Topic: Dispose() and memory management  (Read 2730 times)

0 Members and 1 Guest are viewing this topic.

huma35

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Dispose() and memory management
« on: January 17, 2015, 07:49:00 pm »
Hi! I'm using SFML.NET for my project. My question is: What will happen if I don't use Dispose() function? Does GC ignore disposable objects even though they are out of scope and collectable? Thanks.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Dispose() and memory management
« Reply #1 on: January 17, 2015, 07:53:40 pm »
This question is not SFML-specific, so it's probably better asked elsewhere.

For example, this SO Q&A appears to answer your question: https://stackoverflow.com/questions/4267729/what-happens-if-i-dont-call-dispose-on-the-pen-object

huma35

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Dispose() and memory management
« Reply #2 on: January 17, 2015, 07:57:04 pm »
This question is not SFML-specific, so it's probably better asked elsewhere.

For example, this SO Q&A appears to answer your question: https://stackoverflow.com/questions/4267729/what-happens-if-i-dont-call-dispose-on-the-pen-object

So I think I should call Dispose() for all objects from SFML library since they are unmanaged.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Dispose() and memory management
« Reply #3 on: January 17, 2015, 11:12:50 pm »
You should read carefully all the answers and comments in this SO thread.

Calling Dispose() is only useful if you need deterministic resource destruction. But if you don't care, the GC will correctly collect the instances, and since SFML classes correctly implement the IDisposable interface, unmanaged resources will be correctly destroyed as well.

When something's not clear, you can have a look at how the examples of the SFML.Net SDK are written, and use them as a good reference.
Laurent Gomila - SFML developer

 

anything