Alternative for FreeImage?

BlitzMax Forums/BlitzMax Programming/Alternative for FreeImage?

AvestheFox(Posted 2014) [#1]
Does BlitzMax have a command to free up images? I've looked around without much luck (other than having to install some module or something)


GfK(Posted 2014) [#2]
You don't need to. Automatic garbage collection takes care of it.

Load an image:
Local myImage:TImage = Loadimage("Whatever.png")


Free an image:
myImage = Null


Here you have only one pointer to the image (myImage). When that pointer is Nulled, the garbage collector keeps an internal count of the pointers, so it knows we're done with the image data and dumps it.

Here's another example:
Local myImage:TImage = Loadimage("Whatever.png")
Local myOtherImage:TImage = myImage
myImage = Null


Here, the data WON'T be dumped by GC, because there still exists a pointer to it (myOtherImage).

If you were then to do:
myOtherImage = Null

Then GC would dispose of the image data as the two pointers we created to it, have both been nulled.

One other thing - don't bank on GC clearing the image data immediately, because it doesn't work like that. Garbage collection only happens periodically so it might take a couple of seconds until the data is actually removed.

You can disable the automatic system and handle garbage collection manually, but that's a whole 'nother issue. Never felt the need to do it, myself.


AvestheFox(Posted 2014) [#3]
thanks for that :)


BlitzSupport(Posted 2014) [#4]
Nice explanation there, Gfk.


Matty(Posted 2014) [#5]
Oh....ive not used blitz max but I suppose that means that images referenced within a function will be garbage collected when the scope of the function is exited?

On a related note....what level of scope does blitzmax have? Are variables and resources declared in eg an if block or while loop collected after exiting that block?

Can you declare your own scope blocks with some kind of start and end marker?


Henri(Posted 2014) [#6]
Yes to all except for last question. There is no special marker.

-Henri