n00b-questions ^_^

BlitzMax Forums/BlitzMax Beginners Area/n00b-questions ^_^

CS_TBL(Posted 2005) [#1]
How do I free-up an image? (or anything else for that matter)

i=LoadImage(somefile)
Release i

(Or more specific, in my case, i is a member of a type..)

..leads to a major crash here.. (bmax1.14)


Rimmsy(Posted 2005) [#2]
if you're new to bmx then have a look at http://www.blitzbasic.com/Community/posts.php?topic=41179 for some key differences. One of these is the garbage collection. Since 1.14 garbage collection has become more transparent to the programmer. That is you don't notice it, don't have to call it and don't have to worry (so much) about releasing things. There are a few guidelines to stick to though.

Try using strict mode.
When loading images, etc, use local newImage:Timage=loadimage("etc")
instead of local newImage=loadimage("etc")

this way your image will be "managed" by the garbage collector when it does its rounds. To answer your question you can "release" an image by simply removing any reference to it from your program. So, in this quick example of a program you can see it in action:

If you don't see an immediate change in GCMemAlloced() it's because bmx frees and reallocates the memory in a strange/fast way.

Hope it helps!


REDi(Posted 2005) [#3]
i:timage=LoadImage(somefile)
i = null

oops, to slow :)


Rimmsy(Posted 2005) [#4]
Heh. I forgot to add a Strict to the top of my code. it's alright dave, you're my wife now.


REDi(Posted 2005) [#5]
Dave, my wife would like to use your toilet.


Rimmsy(Posted 2005) [#6]
Dave, my wife says there is a blockage in your toilet.... I've fixed it now.


CS_TBL(Posted 2005) [#7]
ah thx! I'll have a look/test ..

Dunno if I like this high-level resource-management tho.

Ahwell, can't be as bad as my cat bringing a mouse into my studio. ^_^


CS_TBL(Posted 2005) [#8]
if you do this:


bank:TBank=createbank(100)
bank=null
bank:TBank=createbank(10)

Does the first bank get deleted by the GC then?


Floyd(Posted 2005) [#9]
You shouldn't need the bank=Null statement, although it does no harm.

When you assign another value to bank with the second CreateBank there is no longer a reference to the first TBank. The garbage collector will, eventually, reclaim that memory.


CS_TBL(Posted 2005) [#10]
behold


I'm learning bmax by doing this.. :D

two questions:

1 why can't I get the imagewidth/height in that function?
(some error I get..)

2 can I somehow automate that .ev thing in the mainloop? So that upon creation of a gadget like this, things happen automatically?


EOF(Posted 2005) [#11]
1 why can't I get the imagewidth/height in that function?
Since a TImage contains .width and .height fields you can do this:

Print a.image.width

2 can I somehow automate that .ev thing in the mainloop? So that upon creation of a gadget like this, things happen automatically?

See new example here. I've removed width/height fields and replaced them with image.width etc..
Also, I added 'IButton.Ev()'. This calls a function in the IButton type which iterates through a TList (called IButtonList). The list contains references to all the buttons created. Every time you add a new button it is automatically added to the list thanks to the New() method (also present in the IButton type):



CS_TBL(Posted 2005) [#12]
width/height: ok, then why's imagewidth/height in the manual? :P Somehow it looks messy having 2 ways of working in 1 manual..

the list:

I imagined working with a list yeah .. but what I meant was something that looks transparent with the internal gadgets.

So, something that works automatically, just as it does for windows-gadgets.
Something that perhaps creates its own events, so I can have my own codes for my own gadgets..

btw, that 'New' method, is that a constructor actually?


tonyg(Posted 2005) [#13]
Shouldn't you use...
'	a.width=ImageWidth(img)/4 ' try #1

?
Currently you're trying to divide a timage by 4... I think.


CS_TBL(Posted 2005) [#14]
uhm...........

^___________________^


I blame Bmax for it.. I never did such stupidness in B+ :)


CS_TBL(Posted 2005) [#15]
new Q:

How do I get the OS's form/gadget color? (like in Windows: typically 160,160,160 for a window)


EOF(Posted 2005) [#16]
How do I get the OS's form/gadget color? (like in Windows: typically 160,160,160 for a window)
Try this. The example returns the desktop colour. Just modify to suit your needs: