Total Max newbie question

BlitzMax Forums/BlitzMax Beginners Area/Total Max newbie question

Grey Alien(Posted 2005) [#1]
In Blitzplus if I made a temp image with Createmage, I would free it up with FreeImage Temp. This doesn't exist in Max. Delete Temp doesn't work as Delete on it's own is a reserved word. Nor does Temp.Delete work. I read something somewhere about setting the pointer to null and calling the garbage collector, how does this work?

Thanks


Diablo(Posted 2005) [#2]


This should be what your trying todo.


Oddball(Posted 2005) [#3]
Remember though if you are using integer handles for your images you need to Release them.


Grey Alien(Posted 2005) [#4]
like this?
temp = CreateImage(100,100)
'do something
Release temp
FlushMem



Diablo(Posted 2005) [#5]
i think he saying that if you dec the temp image as an int you will need to use realse, so like

tmp:int = CreateImage(100, 100)
'do something
Release tmp
FlushMem


Grey Alien(Posted 2005) [#6]
so if I don't declare it as an Int the preferred method is to set the point to null and call Flushmem?


deps(Posted 2005) [#7]
Yes.

Edit:

Or just use it with something else:
local img:TImage
img = loadimage("img1.png")
img = loadimage("img2.png")
' The first image we loaded will be deleted from memory when we call flushmem



TomToad(Posted 2005) [#8]
Actually, I believe it will be an int if it's not declared. So you need to declare it as TImage if you want to use Null and flushmem()
tmp:TImage = CreateImage(100,100)
'do something
tmp = Null
FlushMem()



Oddball(Posted 2005) [#9]
Sorry. Yes if temp is declared as a Timage type then you can just Null temp, but if it is declared as an integer then you need to Release it.
Global temp:Int
temp = CreateImage(100,100)
'do something
Release temp
FlushMem

or
Global temp:Timage
temp = CreateImage(100,100)
'do something
temp=Null
FlushMem
It is also useful to note that if temp was a Local Timage and lost scope to would be freed anyway.


Grey Alien(Posted 2005) [#10]
OK, cool, thanks. That answers it frm both the Int and TImage angle.


kfprimm(Posted 2005) [#11]
just a small note, call FlushMem() in in your main loop not everytime you release an object.
For example:
While Not KeyDown(KEY_ESCAPE)
Cls

'Do Something

FlushMem()
Flip
Wend



Grey Alien(Posted 2005) [#12]
thanks I read that it might be too slow everytime thus bung in loop.


Oddball(Posted 2005) [#13]
This is a moot point as I believe FlushMem will be replaced by fully automated garbage collection in the next update.


Rimmsy(Posted 2005) [#14]
welcome to the world of bmx, grey


FlameDuck(Posted 2005) [#15]
so if I don't declare it as an Int the preferred method is to set the point to null and call Flushmem?
No.The prefferred method is to not bother with it, and let the GC handle it, when yourreference goes out of scope.

Also, Oddball makes a good point about the "proper" garbage collection comming any day now.


Grey Alien(Posted 2005) [#16]
hmm, OK, it's just an (very) old habit, put the rubbish out myself.


Hotcakes(Posted 2005) [#17]
'Can't Somebody Else Do It?'

It's a good idea to get into the habit of using objects to store your file references instead of integers anyway. It just makes life easier. eg tmp:TImage=LoadImage() instead of tmp=LoadImage()... that... doesn't look easier on the surface... but it is... =]