Safely delete objects used in processBlock


Thank you very much for all the input / teaching, a lot to learn :slight_smile:

Will have a go at it and see if I can get it working!

I think I understand the concept now, but I still can’t get to it work right.
So I’m in need of your help once more :slight_smile:

So my “architecture” right now is:

I have a ReferenceCountedArray “connections” (which is used in the audio thread and the main message thread) and a releasePool.

At the end of my processBlock, I have the information about which points are fully faded out / done and are not needed any more, so I remove them from my connections array ( I’m sure they are not deleted at this point since they are also referenced in my release pool, but is this remove allowed here then?)

But now I have the problem that the nullptr read can happen in the message thread, for example when checking indexes or getting some data from this connection array, since the audio thread could have changed it in the meantime, since the audio thread didn’t need it anymore and removes it (not deleting) so it doesn’t get processed / referenced the next loop around.

I thought about working with local copies for each call involving “connections” like @daniel explained above, but wouldn’t I have to “lock” the copying process then (which would block the audio thread) ?

Thanks in advance for any help how to solve this!