Allocating/Destroying custom types.

Blitz3D Forums/Blitz3D Beginners Area/Allocating/Destroying custom types.

Wrath_of_Zeus(Posted 2003) [#1]
This is really a memory management question I suppose. Custom types, as I understand them, are sort of like linked lists. Everytime I use the New command to create one, it appends my object to a list of ones already created.

My question is about declaring and copying and destroying these types. So for this situation:

1) myThing.MyType = New MyType
2) myOtherThing.MyType = New MyType
3) myThing = myOtherThing
4) delete myOtherThing

It seems to me that line one is not needed. I would guess that myThing is just a pointer, and the New allocates the space, so that line three points the pointer elsewhere, and the space allocated in line one is ignored.

Is that the case? Will the delete in line 4 delete the allocated memory that both myThing and myOtherThing point to? Or does line 3 copy the memory to some new location?


soja(Posted 2003) [#2]
You're right, line 4 will delete the allocated memory that both myThing and myOtherThing point to. The memory allocated from line 1 (i.e. the object) will still be there. The only way to access it would be something like "First MyType" since you assigned the pointer another value.

The New command allocates memory (and puts the new object in the linked list of that type). The Delete command deallocates it (and removes the object from the linked list). Anything.AnyType is essentially just a pointer (to any one of the objects in the type's linked list).


Wrath_of_Zeus(Posted 2003) [#3]
Thanks


WolRon(Posted 2003) [#4]
Since Zeus brought this up, what happens to the memory allocated for myThing? Does Blitz keep track of this and delete it later (when the program ends, I presume)? Or could it possibly be memory left hanging out there unaccounted for?


BlitzSupport(Posted 2003) [#5]
Blitz will clean up everything outstanding on exit...