collectNoStack should be axed
Steven Schveighoffer
schveiguy at gmail.com
Tue Apr 23 14:24:14 UTC 2024
On Tuesday, 23 April 2024 at 07:38:25 UTC, cc wrote:
> On Sunday, 21 April 2024 at 19:28:11 UTC, Steven Schveighoffer
> wrote:
>> If they don't get a printout, they post an angry/confused
>> message on the forums saying
>>
>> ### Y U No work GC?
>
> If a user writes a destructor, and that destructor is never
> called sometime after a `new`, then yes, I think "Why isn't the
> GC working?" is a valid and fair question for that user to ask.
> I don't see any way in which that expectation should be
> considered *unreasonable*. If the answer is "No you don't
> understand, the GC internals such that this- that- and the
> other thing- means you can't have guaranteed destructors", then
> I'd say you've failed to make the sale and the customer is
> right to walk away.
This is a property of ALL GCs, even Java does not guarantee
finalizers will run.
I agree it's reasonable to ask such a question, and we get them
all the time. The thing is, even if we do something as drastic as
not scan live stacks for roots, you still may end up not seeing
the destructor run. This is a fact of life for GC, and it's
better to learn that fact than to try and fight it.
Typically, this is not a question of "why isn't my stuff getting
cleaned up", it's more that they are trying to poke the GC to see
if it's working (usually a small test program). I've done it
too...
And ironically, collecting extra "live" blocks actually hides
from people the true nature of GC and finalization. In truth, you
should never *rely* on the GC to clean up anything but memory.
Resources other than memory should be cleaned up synchronously
when you are done with them, as they are far more rare than
memory.
>
> As an aside, I would observe if one wants them to stay, one
> probably shouldn't be in the habit of calling them "the
> unwashed masses", either.
Sorry, it's just my dry humor. It was more intended as
(good-natured) satire on Walter (I imagine him scoffing at the
insolent nothings that complain about his perfect language) than
an actual slight on the people asking.
-Steve
More information about the Digitalmars-d
mailing list