deleting types

BlitzMax Forums/BlitzMax Programming/deleting types

Can you explain why I 'can not and should not?'


Because if BlitzMAX tries to access any fields of an object after that object has been freed manually, it will either bomb out with an error, or cause some very odd things to happen.

Regarding your code, just do this:

Method freeMedPak()
  if quiz then quizList.Clear()
  FlushMem
End Method


That will delete all the items from the list, and assuming there are no other references to those items, they will also be freed during the call to FlushMem. That is the great thing about BlitzMAX' memory management - it saves a lot of effort.

Edit: To clarify about memory management. Unless you are dealing with other external APIs, you can effectively forget about it. Just call FlushMem:

(1) On a regular basis during the normal game (usually once during each game loop for example)

(2) After operations where a lot of memory has been allocated (eg. loading a game level, or after reading the contents of a file line by line).