How can I signal a master object that a resource handle is no longer used, from within the resource class's destructor?

realhet real_het at hotmail.com
Fri Jul 4 08:22:25 UTC 2025


On Saturday, 28 June 2025 at 08:11:53 UTC, realhet wrote:
> On Thursday, 26 June 2025 at 16:40:10 UTC, Steven Schveighoffer 
> wrote:
>> On Tuesday, 24 June 2025 at 08:48:16 UTC, realhet wrote:

For those who run into this problem: These are really illegal 
things in the destructors:
- GC allocation.
- synchronize() block when it contains a secret hidden GC 
allocation. This can enter into a freezing state, as the hidden 
mutex object will never be created. (just my speculation)

So for the unlimited sized linked list I used the help of AI to 
make me a freeList and use core.stdc.alloc() and free().  (I 
normally don't like that AI LLMs, are coding in DLang in low 
level C style, not using the high level D functional goodies, but 
this time it was a perfect job for it.)

And for the synchronized() block: Now because in put() the buffer 
can be replaced when it's growing, I use synchronized(this) both 
in put() and fetch(). And in the constructor, I do this:
```d
synchronized(this) { asm{ nop; }}
```
This is the very first synch block for 'this' and it does a GC 
allocation. That must NOT happen inside the destructor.


 From now I will have a 100% guarantee that the resource (Texture 
handles in my case) will not leak.  And it's guaranteed by the GC 
fully automatically.  And if I want to do it nicely I can call 
destroy manually from any thread.


More information about the Digitalmars-d-learn mailing list