Freeing Images Within Types

BlitzPlus Forums/BlitzPlus Programming/Freeing Images Within Types

Grey Alien(Posted 2005) [#1]
If I make a type and one of the fields is a pointer to an image that I load in or create, when I call Delete TheType, does Blitz automatically free the image as well or should I make a destructor?

Also if I need a destructor so that I can create and free TheType multiple times in my game, would I need a destructor if TheType is only declared once as I know that blitz attempts some kind of cleanup on exit? In fact does Blitz free up types on exit if you don't!?

Cheerz


Snarty(Posted 2005) [#2]
Firstly, you will need a constructor/deconstructor. But, to be honest this is good practice in any case.

And as for cleaning up, you could always use:
Delete Each TheType
Images are automatically unloaded on exit.


Grey Alien(Posted 2005) [#3]
OK, thanks, guess I'd better make a destructor then.

Thing is I have a template type that the actual images are loaded into and all the other types just point their image pointers at the template type's images. Therefore when I free the non-template types, I don't need to free the images as they were only pointers. But I do need to free the template type images on exit (I suppose). I was just wondering if I call Delete TemplateType will blitz kill the images for me? In fact if I don't even call Delete TemplateType, will Blitz kill the type AND the images? Get it? I am just trying to be lazy and also to avert paranoia.

See I know that blitz kills images on exit but what if the pointers to them were part of a type that you have already deleted. Doesn't this leave the images without pointers, thus unfreeable, or does blitz keep track of images on its own?


Snarty(Posted 2005) [#4]
Blitz never deletes the image data, when you delete a type it just frees the pointer(s).


Grey Alien(Posted 2005) [#5]
well that definitely means I need a destructor, ho hum.