Does this code have a memory leek?

BlitzPlus Forums/BlitzPlus Programming/Does this code have a memory leek?

Grey Alien(Posted 2005) [#1]
Does this example code have a memory leak?

	Local image% = CreateImage(100,200)
        For i = 0 to 3
	  Local tmpimage = CopyImage(image%)
   	  DrawImage tmpimage, 0, 0
        Next


i.e. when it loops and calls CopyImage, is the previous tmpimage image freed up automatically each time or do I need a line after Draw image that says FreeImage tmpimage?

Also if CopyImage recogises that an image already exists does it just reuse it instead of freeing and recreating? If so, what happens if I changed the size of image1 during the loop (i.e. if I shrunk it, would the excess memory be freed?)

get it?


Beaker(Posted 2005) [#2]
You need to freeimage.


WolRon(Posted 2005) [#3]
CopyImage creates a new image and stores its handle in the variable you specify. Since, you specified the same variable, the old handle would be overwritten, but the image would still exist.

Use an array or Types to keep track of the images.

tmpimage(i) = CopyImage()

or

tmpimage.ImageHandleType = New ImageHandleType
tmpimage\handle = CopyImage()


Grey Alien(Posted 2005) [#4]
Thanks guys, thought I probably needed FreeImage. I would have in any other language but I am a bit confused about what Blitz does and doesn't free up so I tend to free it all to be safe anyway.


WolRon(Posted 2005) [#5]
Blitz will FreeImage the image at the programs End or EndGraphics but you need to do it manually any other time.