Non-freeing GC memory management
Minas Mina via Digitalmars-d
digitalmars-d at puremagic.com
Tue Nov 17 21:56:36 PST 2015
On Wednesday, 18 November 2015 at 05:49:00 UTC, tcak wrote:
> On Tuesday, 17 November 2015 at 19:32:05 UTC, Adam D. Ruppe
> wrote:
>> On Tuesday, 17 November 2015 at 19:27:15 UTC, tcak wrote:
>>> As far as I know, GC has a separate thread that stops all
>>> other threads periodically to clear the unused memory fields.
>>
>> That is a common misconception...
>>
>>> What disadvantages would we have if GC was to be freeing
>>> memory only when allocation is requested, and not checking
>>> periodically?
>>
>> This is what it actually does now.
>
> That means object destructors are to be called only when a new
> allocation happens? But not all allocations end up with this.
> If this is so, this behaviour of GC encourages to call destroy
> (or was it clear?) on objects manually to manage the memory
> more efficiently.
That's correct.
But you don't have to do it manually though, as you can always
wrap your object inside a Unique!T.
http://dlang.org/phobos/std_typecons.html#.Unique
More information about the Digitalmars-d
mailing list