POV-Ray : Newsgroups : povray.off-topic : Learning C# : Re: Learning C# Server Time
29 Jul 2024 06:26:37 EDT (-0400)
  Re: Learning C#  
From: Darren New
Date: 29 Sep 2012 19:34:44
Message: <50678594$1@news.povray.org>
On 9/29/2012 14:17, Orchid Win7 v1 wrote:
> In short, writing a correct destructor is a nightmare.

Not really. Writing a complicated class that also has a destructor is a 
nightmare. If you have a destructor on a class that has anything more than a 
reference to the object you want to destruct, you're probably doing it 
wrong. If you're doing more than wrapping the non-GCed resource, you're 
doing too much work in that class.

That said, no, destructors aren't especially useful except for logging that 
you you forgot to explicitly free your resource. :-)

>> In C++ destructors are useful for more than just freeing memory. For
>> example they are commonly used in things like locks:

Personally, I find that sort of thing terribly confusing. I suppose you get 
used to having variable declarations actually being control flow statements, 
but I find it rather bizarre.

>> It's handy because you don't need to any special code to
>> make sure that the destructor is called when the function is exited.

I prefer the Sing# method, wherein if you have a variable that needs to be 
tracked, and you let it go out of scope without disposing it, the code 
doesn't compile. You can still get resource leaks with the C++ method, if 
your structures are complicated enough.

-- 
Darren New, San Diego CA, USA (PST)
   "They're the 1-800-#-GORILA of the telecom business."


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.