how do you mix ref counted types and non- at nogc algorithms

Steven Schveighoffer schveiguy at gmail.com
Wed Jul 8 12:30:09 UTC 2020


On 7/8/20 7:26 AM, ikod wrote:
> Hello,
> 
> I have ref-counted type (keeps reference to mallocated memory) which I 
> would like to release as soon as possible (when I have no refs from my 
> code).
> 
> The problem is - standard algorithms can use some GC allocations to keep 
> refs to my data until GC is collected, so that I have no control over 
> memory consumption when non- at nogc algorithms applied to RC data.
> 
> Right now I have to avoid something like my_data.splitOn(), but is there 
> any better solution?

My solution to this was to use the GC for ref counted data.

See here: http://schveiguy.github.io/iopipe/iopipe/refc/RefCounted.html

This way, the resources represented by the type (generally things like 
files or malloc'd items) are cleaned up, but the memory is still safe to 
use.

-Steve


More information about the Digitalmars-d mailing list