Delete An Entity Question

Miscellaneous Forums/General Discussion/Delete An Entity Question

how do i do it... myEntity=NULL or myEntity=0???

thx

--Mike

Not 100% sure what you mean but when I free an entity it is basically just:

freeentity myentity
myentity=0


myEntity.myType = new myType
;do stuff
delete myEntity


that's in BlitzPlus which is the same as in Blitz3D. You may want to zero the pointer afterwards with myentity=0 just in case you test it later for null and it still points to the old freed memory. Setting myEntity to 0 before calling delete is a nono as you've just made a memory leak! Sorry if you mean something else by myEntity that I haven't grasped.

If myEntity is a type instance, use myEntity=Null, else use myEntity=0. That is, Null can only be used with types. I seem to be saying this a lot, lately.

k... got it... many thx...

just added DeleteObject to my OO engine...

--Mike

what the hell, so in Blitz 3D you don't call Delete, you just set to null and that free's it without making a memory hole? That would be a massive no no in other languages, C/C++/C#, Delhi, VB etc.

No, Grey - you have to delete it, beforehand. I assumed Red simply wants to set his object handles to Null/0 afterwards for some reason.

let's hope he understood correctly.

i got it guys... i think...

instances of user defined types are nulled, entities are set to zero...

is that right :)

thx again

--Mike

In Blitz (and only in Blitz) a pointer to a type object which has been Delete()d will evaluate to Null.

Type foo
	Field x
End Type

f1.foo = New foo
f2.foo = f1
Delete f1
If f2 = Null Then Print "told you so"


Red: Types, Images, Sounds must be killed off with Delete first then in theory they are set to Null or 0 automatically, but not always depending on if they are types or images/sounds.

octothorpe: Yeah I don't bother with setting them to 0 or Null, but I DO with images and sounds as they do not get zeroed and you can run into trouble if you try to do this:

If MyImage<>0 then Delete MyImage