Sterlings Handy Hint #1

Blitz3D Forums/Blitz3D Beginners Area/Sterlings Handy Hint #1

Sterling(Posted 2005) [#1]
1. Be sure to always free any textures/images once you have finished using them.

Opening an image (eg. myimage=loadimage("hello.tga") uses video memory for that image, if you use the same command again(even for the same image) another piece of memory will be reserved for that image therefor eventually using up all your video memory causing you large amounts of stress as your game runs really slowly.

For some reason I assumed(NEVER assume anything kids!....) if I opened and image with the same variable as before it would either free the memory used previously or it would be replaced with the new image however this is not the case.

So in conclusion always free you textures/images/entities etc when you have finished with them.


Tobo(Posted 2005) [#2]
Good tip, Sterling.

I wondered why my bouncing ball(s) screen saver would run slower and slower when I ran it over & over again.


Ross C(Posted 2005) [#3]
http://www.blitzbasic.com/Community/posts.php?topic=39205

Some more handy tips :o)


jfk EO-11110(Posted 2005) [#4]
And BTW if you open an Image with the same variable twice, you even lose control over the first one, so you even won't be able to free it. But that's just the nature of the way this works.
BTW. I'd also recommend to set a variable to zero if you once freed it's resource, eg:

freeimage img
img=0

This way you'll be able to detect if a variable is still "holding" some resouces, eg.

if img<>0 then freeimage img
img=loadimage("i2.bmp")