Hi,
if I define a finalizer for a specific class and later on I inherit from that class, is that finalizer also called, or do I have to pass this inherited finalizer to new (which makes problems, because it has a different signature and can be hidden) ?
type
TFoo = ref object of TObject
data: Pointer
proc newFoo(): TFoo =
new (result, proc (self: TFoo) = dealloc(self.data))
result.data = alloc0(1000)
type
TBar = ref object of TFoo
name: string
proc newBar(): TBar =
new(result)
result.name = "bar"
var b = newBar()
b = nil
The finalizer is part of the RTTI which is per object type; this means it is not inherited whatsoever and you need to do:
proc newBar(): TBar =
new(result, proc (self: TBar) = finalizeFoo(self))
result.name = "bar"
Thinking about it, inheritance of finalizers seems pretty easy to implement ... Feature request?
Since the finalizer is part of the RTTI and it is allowed to pass an anonymous finalizer, I think it would be consequent that the runtime takes care that each inherited finalizer will be called - but this will break existing code which takes care for this already (don't know how much it is)
I will make a feature request.