Total Max newbie question
BlitzMax Forums/BlitzMax Beginners Area/Total Max newbie question
| ||
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 |
| ||
This should be what your trying todo. |
| ||
Remember though if you are using integer handles for your images you need to Release them. |
| ||
like this?temp = CreateImage(100,100) 'do something Release temp FlushMem |
| ||
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 |
| ||
so if I don't declare it as an Int the preferred method is to set the point to null and call Flushmem? |
| ||
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 |
| ||
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() |
| ||
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 FlushMemIt is also useful to note that if temp was a Local Timage and lost scope to would be freed anyway. |
| ||
OK, cool, thanks. That answers it frm both the Int and TImage angle. |
| ||
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 |
| ||
thanks I read that it might be too slow everytime thus bung in loop. |
| ||
This is a moot point as I believe FlushMem will be replaced by fully automated garbage collection in the next update. |
| ||
welcome to the world of bmx, grey |
| ||
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. |
| ||
hmm, OK, it's just an (very) old habit, put the rubbish out myself. |
| ||
'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... =] |