I guess this only happens with the New and Delete methods.
All other user-defined methods don't get called twice.
Type TestA
Method New()
Print "New TestA-type"
End Method
Method Delete()
Print "TestA-Type deleted"
End Method
Method Something()
Print "Printing something from TestA"
End Method
End Type
Type TestB Extends TestA
Method New()
Print "New TestB-type"
End Method
Method Delete()
Print "TestB-Type deleted"
End Method
Method Something()
Print "Printing something from TestB"
End Method
End Type
Local a:TestA = New TestA
a.SomeThing()
Print "-----"
Local b:TestB = New TestB
b.SomeThing()
Print "-----"
a = Null
FlushMem
Print "-----"
b = Null
FlushMem
Print "-----"
This code outputs:
New TestA-type
Printing something from TestA
-----
New TestA-type
New TestB-type
Printing something from TestB
-----
TestA-Type deleted
-----
TestB-Type deleted
TestA-Type deleted
-----
You see that when creating (and deleting) a TestB type-instance, both the TestA- and TestB- "New" (and "Delete") methods are called.
First, the TestA object is created (New-method of this object is executed upon creation) and then that object is "extended" by the TestB object, resulting in the second New-method being executed.
How could you extend the TestA object by a TestB object, if a TestA object didn't exist in the first place?
When you call the method "Something" from the TestB type, only the TestB-method is executed, because you've overridden the Something-method of the TestA object (the TestA-Something method can still be executed by using Super.Something).
After that, you delete the TestB object and therefore, the TestA object isn't required anymore, so is deleted too, resulting in the execution of both "Delete" methods in reverse order.