FreeImage()

BlitzMax Forums/BlitzMax Beginners Area/FreeImage()

Airilsm(Posted 2006) [#1]
How do we free our loaded image? Like FreeImage() in B+

Actually I try to create a program to rescale all my JPG file in my computer into half size. So I have to load it, rescale, save it and free it. Then I do for the next one until all finish. This is a half way work..

'Graphics 800,600
diro$="C:\"
into(diro$)

Function into(diro$)
	dir=ReadDir(diro$)
	Repeat
		t$=NextFile( dir )
		If t="" Exit
		If t="." Or t=".." Continue
		If FileType(diro$+t)=2
			into(diro$+t+"/")
		EndIf
		If Upper(Right(t,3))="JPG"
			print diro$+t
			'temp=LoadImage(diro$+t)
			'If temp
			'	DrawImage temp,0,0
			'	Flip
			'	Delay 2000
			'	ProcessRescale()
			'	FreeImage(temp)
			'EndIf	
		EndIf
	Forever
CloseDir dir
End Function
function ProcessRescale()
end function


Without FreeImage() the memory is full!!!?!?!?!
So I rem it for a while until I found a solution


degac(Posted 2006) [#2]
temp=LoadImage(name$)
DrawImage temp,x,y
Release temp

or better solution

temp:timage=LoadImage(name$)
Drawimage temp,x,y

Temp=NULL


tonyg(Posted 2006) [#3]
You shouldn't need to do anything other than use...
local temp:TImage=loadimage(blah)
If you're up to date with your Bmax levels the automatic Garbage Collector will free unused memory.


Dreamora(Posted 2006) [#4]
He is using int handles, in which case the GC won't do anything. So mainly, the only thing needed is the type declaration mentioned by both of you :TImage on the temp declaration (and using strict!)


tonyg(Posted 2006) [#5]
Is that not what I said then!??!


Dreamora(Posted 2006) [#6]
yes and no. Without strict, yours will lead to problem as variable scoping only exists within strict. otherwise local is "useless" in a longer source as it will cause redefinition compile errors


tonyg(Posted 2006) [#7]
variable scoping only exists within strict.

Is that right?
I thought...
Strict mode forces you to declare all variables before use.
(Bmax doc)
but variable scoping still exists without it.


Dreamora(Posted 2006) [#8]
Nope ... sadly not. Variable scopes are only activated when using one of the 2 stricts. Don't ask me why thought ... :-)


tonyg(Posted 2006) [#9]
I must be misunderstanding what you're saying.
Have you got any code which shows what you're saying?


Dreamora(Posted 2006) [#10]
for local i:int = 0 to 10
  print i
next

for local i:int = 0 to 10
  print i
next


This one fails for dublicate identifier i, but works if you add a strict at the top.


Grisu(Posted 2006) [#11]
I was told not to free any image by hand?
The mighty GC does the job for you.


Dreamora(Posted 2006) [#12]
If you use :TImage on declaration, then yes.

If you don't use it and use int handles then you manually have to free anything as the GC does not touch int handle based ressources at all. (but it is no intelligent idea to use them. They are 5 - 30 times slower than correctly typed objects as BM is not focused around int handles as B3D was)


Grey Alien(Posted 2006) [#13]
I free mine by setting them to null in certain cases, and that's fine.


tonyg(Posted 2006) [#14]

for local i:int = 0 to 10
print i
next

for local i:int = 0 to 10
print i
next



This one fails for dublicate identifier i, but works if you add a strict at the top.


Isn't that just a bug (or a 'feature') rather than "variable scoping only exists within strict."?
I always use Strict so I'm not that fussed really just got confused what you are trying to say.