Deleting types within types question.

Blitz3D Forums/Blitz3D Beginners Area/Deleting types within types question.

This is something that has been bugging me for a while, but I don't know the correct answer.

let's say I have a type inside another type, like this

type vector2
 field x#
 field y#
end type

type obj
 field pos.vector2
end type

o.obj = new obj
o\pos = new vector2
o\pos\x = 1
o\pos\y = 2


Now when I want to delete the type, I do this

delete o\pos
delete o


but do I need to delete the sub-type, or can I just use the following?

delete o


The first method is the correct one.

The second method will cause a memory leak and vector2 types will still be hanging around.

Obviously, if you delete all vector2's first you don't need to touch the pos.vector2 as the type instance it points to is already gone.

Thanks. I just realized it was pretty easy to see by just doing this.

Type vector2
 Field x#, y#
End Type

Type body
 Field pos.vector2
End Type

b.body = New body
b\pos = New vector2
b\pos\x = 1 : b\pos\y = 2

printdetails()

For b = Each body
	;Delete b\pos
	Delete b
Next

printdetails()

WaitKey()

Function printdetails()
	Print "contents of body"
	For b.body = Each body
		Print Str$(b)
	Next

	Print "contents of vector2"
	For v.vector2 = Each vector2
		Print Str$(v)
	Next
	Print 
End Function



Woah, I was just wondering yesterday if putting a type within a type is possible. Thanks for saving me some time ;)