Advice wanted on garbage collection of sockets for c++ programmer using D
bauss via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 27 12:47:26 PDT 2017
On Tuesday, 27 June 2017 at 10:14:16 UTC, Jonathan M Davis wrote:
> On Tuesday, June 27, 2017 09:54:19 John Burton via
> Digitalmars-d-learn wrote:
>> [...]
>
> Arguably, std.socket should have used structs instead of
> classes for sockets for precisely this reason (though there are
> some advantages in using inheritance with sockets). But yes,
> calling close manually is the correct thing to do. Relying on
> the GC to call a destructor/finalizer is error-prone. There is
> no guarantee that the memory will ever be freed (e.g. the
> runtime could choose to not bother doing cleanup on shutdown),
> and even if the GC does collect it, there are no guarantees
> about how soon it will do so. However, if you keep allocating
> memory with the GC, then over time, the GC will collect
> GC-allocated memory that isn't currently being used so that it
> can reuse the memory. So, you really don't need to worry about
> the memory unless it becomes a bottleneck. It will be collected
> and reused, not leaked.
>
> [...]
I agree with that it should have been structs. The inheritance
issue could be fixed by having a private member of the struct in
a class, that way there could still be a class wrapper around it.
More information about the Digitalmars-d-learn
mailing list