Stop writeln from calling object destructor

Steven Schveighoffer schveiguy at gmail.com
Mon Oct 3 11:08:00 UTC 2022


On 10/2/22 12:21 PM, data pulverizer wrote:
> I've noticed that `writeln` calls the destructor of a struct multiple 
> times and would like to know how to stop this from happening. It has 
> become a very serious problem when working with objects that have memory 
> management external to D.

I know you already solved the problem, but just for future reference, if 
you use something like `RefCounted`, you can avoid copying and 
destruction until everyone is done with the object. This is how my io 
library works, the IO objects are non-copyable, and you wrap them in 
`RefCounted` if you want to copy them.

-Steve


More information about the Digitalmars-d-learn mailing list