realbasic-plugins
[Top] [All Lists]

Re: Event defines a Byref argument of type Variant

To: REALbasic Plugins <realbasic-plugins at lists dot realsoftware dot com>
Subject: Re: Event defines a Byref argument of type Variant
From: Alfred Van Hoek <vanhoek at mac dot com>
Date: Sun, 29 Jan 2006 13:13:47 -0500
Delivered-to: realbasic-plugins at lists dot realsoftware dot com
References: <9d4cb5482cf867a2bda9cfe0e26d6ef5 at mac dot com> <c7940e20601290807k31e8b8q45e280a69b4b1283 at mail dot gmail dot com>

On Jan 29, 2006, at 11:07 AM, Jonathan Johnson wrote:

On 1/29/06, Alfred Van Hoek <vanhoek at mac dot com> wrote:
Given an event declaration like:

"GetValue(selector as Integer, Byref Value As Variant) As Integer"

The event is very simply implemented:

Value = new Script // note: a plugin class not derived from RBScript

return 0

In plugin code we extract the script instance from the variant, and it
appears that the refcount to this class remains 1 after returning from
the event. Don't understand this, shouldn't the instance be unlocked
automatically by RB once we loose scope, at least when returning to the
main event loop?

It should only have one reference count. However, I think you'll find
that the value parameter you passed in byref actually contains a
different variant than you originally passed in. If the original
variant only has one reference, then it should be freed.


Thanks Jon,

So it seems:

Hmm, the refcount of "Value" before and after "Value = new Script" appears to be 2 in both cases, and then goes to 1 when leaving the event. It does not matter if we declare the arg as a Variant or Object.

Here again relevant code:

/*8*/{ "GetValue(selector as integer, BYREF value As Object) As Integer" },

long (*_fp)(REALcontrolInstance cntl, long, REALobject*);

_fp = (long(*)(REALcontrolInstance cntl, long, REALobject*))
                                REALGetEventInstance(me->self, &myEvents[8]);

if (_fp)
{
        REALobject theValue = 0;
        err = _fp(me->self, 15, &theValue);
        me->scriptObject = theValue;
}

The event implementation is now:

  dim npv As new NPVariants

  // testing the refCount and address of "value"
  npv.DEBUGOBJECT value

  dim myScript As new Script
  // testing  the refCount and address of "myScript"
  npv.DEBUGOBJECT myScript

  value = myScript

  // testing the refCount and address of "value"
  npv.DEBUGOBJECT value
  return 0


And the console reports:

Object: Refcount->(2), Address->(190ae04)
Object: Refcount->(2), Address->(190ae04)
Object: Refcount->(2), Address->(190ae04)

Don't know why myScript has the same address as "value", while when leaving the event "me->scriptObject " has a different address, and a refCount of 1.

Alfred

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>