In AngelScript an object handle is a reference counted pointer to an object. In the scripts they are used to pass the objects around by reference instead of by value. Depending on how an application type is registered the type will support handles.
Whenever the object handle is passed by value from the application to the script engine, or vice versa its reference should be accounted for. This means that the application must release any object handles it receives as parameters when it no longer needs them, it also means that the application must increase the reference counter for any object handle being returned to the script engine. This also applies to the generic calling convention.
A function that creates an object and returns it to the script engine might look like this:
A function that receives an object handle from the script and stores it in a global variable might look like this:
A function that retrieves a previously stored object handle might look like this:
A function that receives an object handle in the parameter, but doesn't store it looks like this:
The application can use auto handles (@+) to alleviate some of the work of managing the reference counter. When registering the function or method with AngelScript, add a plus sign to the object handles that AngelScript should automatically manage. For parameters AngelScript will then release the reference after the function returns, and for the return value AngelScript will increase the reference on the returned pointer. The reference for the returned value is increased before the parameters are released, so it is possible to have the function return one of the parameters.
The auto handles works the same way for the generic calling convention.