Now, answering to your reply:
I tried AS_MAX_PORTABILITY in windows, and the same bug is reproduced exactly the same way. However, I use aswrappedcall and the factory/add/release functions are the same for either native and generic conventions.
I logged the ref behaviors and there is something weird happening:
=> Before ResetGlobalVars
=> [RefCounter:057265A4]: Init with reference counter at 1
=> [RefCounter:05726700]: Init with reference counter at 1
=> UIButton Constructor
=> [RefCounter:05726598]: Reference added: Now 1
=> [RefCounter:05726598]: Reference removed: Now 0 (Releasing)
=> UIButton Destructor
=> After ResetGlobalVars
This is very weird. First, there are two inits and I don't know where they come from, I only have one global variable, UIButton button; declared outside any function.
Then, its mem address doesnt match the later one (unless this is normal with polymorphism? )
Finnaly, there is a AddRef call that puts the ref counter at 1, which is impossible since it begins at 1, and if it ever reaches 0, it releases..
Could this be something wrong with my constructors? They are declared in the plain old way "Constructor()", the constructor chain is: UIButton() calls UIControl() which calls RefCountable().
The destructor in RefCountable is declared virtual.. The UIButton is properly initialized in the constructor, the ref count goes to 1, then somehow it is 0, when addRef is called on the exact same address.. This didn't happen with the build of angelscript i had before..