Type Int or TGadget

BlitzMax Forums/BlitzMax Beginners Area/Type Int or TGadget

Yue(Posted 2016) [#1]
Window:TGadget = CreateWindow
or Window:Int = CreateWindow




Some dramatic difference? or is that complicate life for this.


Henri(Posted 2016) [#2]
Hi Yue,

always use TGadget, because this is what CreateWindow natively returns. If you use Int then conversion to integer handle is made.

-Henri


TomToad(Posted 2016) [#3]
Using Int is the old way of doing it. BMax will create an object handle to the type. Unfortunately, your program could create a memory leak if the handle isn't properly released. When you use TGadget instead, the garbage collector will take care of freeing the objects for you.
Local a:Int

For a = EachIn MyTypeList
	Print a.name
	Release a '<-- without this, you would have a memory leak
Next

'-----------------------
Local a:MyType

For a = EachIn MyTypeList
	Print a.name 'no need to release, the GC will take care of that
Next

If you use Strict or Superstrict at the top of your code, which you should be doing, will disallow the use of object handles.