auto classes and finalizers
Georg Wrede
georg.wrede at nospam.org
Thu Apr 6 12:22:10 PDT 2006
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.
This could be called a "linked-list-invariant". :-)
More information about the Digitalmars-d
mailing list