Thanks for all the info, Mike. I come from a C# background, so I have pretty much 0 experience when it comes to handling memory myself(let alone working with a binding to another language) and I haven't read my D book as much as I would like.

I'm not quite sure what you are referring to when you say, "I tested this." Which? Freeing the image in a destructor?

I tried putting destroy in the destructor like the code I wrote. Like I said, it gave me no memory errors, but I don't actually know if it even does anything. I honestly think that it is weird to not be able to rely on destructors like this. To me, it makes sense that the destructor would be a part of the garbage collection, but again I don't have any sort of experience with memory management. I find it kind of silly to have something like a destructor built into a language, but it not being reliable and more or less something to be completely ignored altogether. I do understand that in most cases this can be so, as the GC will free up the memory itself, but in some cases it could be useful to know your destructor will free up the resources the GC can't.


The scope(exit) in the main method ensures that this termination chain is run every time the app exits regardless of the reason

This is good to know. I read about this, but haven't used it yet. Wouldn't the destructors get called at this point?



Also, what about something like this?

void main(string[] args)
{
   {
      init();
      gameLoop();
}<-Wouldn't the destructors get called here? Or would the GC run first? }<-And what would happen here? Would GC be run again after the scope is left?


I am just trying to understand the language better. So far it seems that the only way to prevent memory leaks when memory is being allocated outside of D is to manually delete those objects yourself and to not rely on the destructors. I will make sure this happens in the future!

Sorry if I say silly things. I am but a young programmer trying to gain knowledge!

Reply via email to