auto classes and finalizers
Lars Ivar Igesund
larsivar at igesund.net
Thu Apr 6 12:29:32 PDT 2006
Georg Wrede wrote:
> kris wrote:
>> Sean Kelly wrote:
>>> kris wrote:
>>>> Jarrett Billingsley wrote:
>>>>>
>>>>> Hmm. 'auto' works well and good for classes whose references are
>>>>> local variables, but .. what about objects whose lifetimes aren't
>>>>> determined by the return of a function?
>>>>>
>>>>> I.e. the Node class is used only in LinkedList. When a LinkedList
>>>>> is killed, all its Nodes must die as well. Since the Node
>>>>> references are kept in the LinkedList and not as local variables,
>>>>> there's no way to specify 'auto' for them.
>>>>
>>>> Heck, the LinkedList dtor /cannot/ rely on the nodes being valid if
>>>> they are also managed by the GC :)
>>>>
>>>> So, as I understand it, one cannot legitimately execute that example.
>>>
>>> ...unless the LinkedList has a deterministic lifetime :-)
>>
>> <g> Touché !
>
> Hey, hey, hey...
>
> If anybody deletes stuff from a linked list, isn't it their
> responsibility to fix the pointers of the previous and/or the next item,
> to "bypass" that item??????
>
> The mere fact that no "outside" references exist to a particular item in
> a linked list does _not_ make this item eligible for GC.
>
> Not in the current implementation, and I dare say, in no future
> implementation ever.
>
> In other words, it is _guaranteed_ that _all_ items in a linked list are
> valid.
>
Not if the linked list is circular (such that all items is linked to), but
disjoint from the roots kept by the GC. This memory will be lost to a
conservative GC, but can be detected some of the other types around.
More information about the Digitalmars-d
mailing list