SFML community forums
Bindings - other languages => D => Topic started by: RobotGymnast on February 03, 2011, 01:01:47 pm
-
Does one need to bother disposing everything using .dispose(), or is it just if I want to invalidate it prematurely?
-
Does one need to bother disposing everything, or is it just if I want to invalidate it prematurely?
If D is anything like C anything that isn't an explicitly allocated pointer goes out of scope with the pair of brackets it's declared in.
-
So it turns out that it's completely necessary to dispose everything, like Images, otherwise memory leaks result, and exceptions are soon thrown, as demonstrated in this simple piece of code:
import dsfml.graphics.all;
void main()
{
while(true)
auto rect = new Image(1024, 1024);
}
We can use .dispose() inside the loop, to free the allocated memory;
the only problem is, this throws exceptions and/or gives access violations when the objects are ACTUALLY destroyed, as demonstrated in:
import dsfml.graphics.all;
void main()
{
auto rect = new Image(1024, 1024);
rect.dispose();
}
What's the proper procedure here? Either memory leaks or access violations?
Edit: Fixed by calling GC.collect() manually once-in-a-while.
-
GC.collect is called automatically.
It's triggered when you try to allocate memory and the GC has no mor eleft. In this case, the GC try to free memory before asking more to the system.