GC has a "barbaric" destroyng model, I think
Andrey Derzhavin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Feb 12 04:10:21 PST 2015
OK. there is some example:
// we're using an OpenGL
class A
{
protected int m_tex;
this()
{
// texture has been created in video memory. there is no GC
resource.
glGenTexture(1, &m_tex);
glTexImage2D(....); // texture in video memory
}
~this()
{
// release texture in video memory
glDeleteTextures(1, &m_tex);
}
}
void foo()
{
// we do some operations...
A[] arrA = new A[1_000_000];
for (int i; i<arr.length; i++)
arrA[i] = new A(); // generate texture
// do some operations... and return without explicit disposing
of arrA
}
main(...)
{
while(app.isNotExit)
{
foo();
}
}
if GC does not guarantee the calling of dtor we can't be sure
that some textures will be destroyed.
It will be followed by overflowing of the video memory.
And it is obvious, becouse we have no way to detect when the
objects are destroyed.
The video memory will leaks.
More information about the Digitalmars-d-learn
mailing list