Forum Discussion

dev42's avatar
dev42
Visitor
11 years ago

The quest to understand refcnt

"RokuMarkn" wrote:
The ref count is the number of variables referring to the object. It's set to 1 when you do CreateObject, and it get incremented every time a new variable is set to refer to that object, and decremented every time any such variable is modified or destroyed.

In answer to another one of your questions, all local variables are destroyed when the containing function exits. There is no need to set a variable to invalid unless it's going to remain in scope.

Also, I've updated section 4.3 of the Brightscript Language Reference to explain a bit more about references and such. I'd appreciate any feedback if it isn't clear.

--Mark
( I moved it here as it really is another topic. from, here)

linky (Area 42 errr section): 4.3 Intrinsic types and object types

[Edit: Just noticed section 4.4 Use of wrapper functions on intrinsic types, which may null and void some of my comments. Maybe. 😛 ]

Feedback:
  • Capitals "issue"(?)/ possible confusion: doesn't Java designate lower case as intrinsic and first letter Capital as Object? Furthermore, you weren't consistent and used "integer" further down. Yes, BrightScript is BrightScript and can/should have its own conventions. ( Sorry if nitpicking, but trying to err on helpful. ) Perhaps expand, "An object type is one of Array, Associative Array or Brightscript Component." to include more BrightScript correct code? ie roArray, roAssociativeArray? Or is there an instrinsic "Array" type too? Also make connection between Integer and roInt? roString etc and/or make a table to show the intrinsic type in one column and the BrightScript object in another? Although that might just be more confusing. Dunno.
  • In first example, could you add: b = 2319 ' does not modify a ( For those ... like moi. )
  • the part about autoboxing no longer being necessary went over my head.

Other than that, I'm still baffled why I had 5 refcnts to my roScreen. I'll have to dig into the code, but if I'm passing the <roScreen> as a parameter ( something I'm ready to change very soon, now that I've found GetGlobalAA() ) it seems to me that all the references are the parameters in these functions. Maybe I'm "seeing" it incorrectly and there are in fact many references to the same <roScreen> but instead of depth it is breadth? :idea: IOW, if I have a roList of Objects and each object has a reference to <roScreen> then they would all stay active as long as each Object in my roList stays alive? As Belt would say, "Dun-dun-dunnnnnn!"

peace & 42

16 Replies