[Openroad-users] Question about the value and useof.InstanceReferences

Bodo Bergmann Bodo.Bergmann at ingres.com
Thu Nov 15 09:17:22 EST 2007


Peter,
 
CurObject is not in the object itself, but a (well documented) variable
in the scope of each method.
 
And the fact that your 4GL code didn't create the reference doesn't mean
there is no additional reference.
 
E.g. if you insert an entryfield into a stack field (using InsertChild
method),
there will be an increase in the stackfield's reference counter
as the ParentField of the entryfield refers to the stackfield.
 
So all output in your example is as I expect it.

Imagine a scenario where it would be possible to run the method in a
separate thread (asynchronously).
Then - if the reference count remains 1 - the object could be removed
from memory after starting the method
when the procedure is finished, as the InstanceReferences would then be
decreased to 0.
That is the method would then work on an object which doesn't exist
anymore - and crash.
 
The main purpose of InstanceReferences is to know if there are more
references than expected,
in order to check for circular references, etc.
So in a method of a class you can always expect 1 additional reference
to the object.
 
Another example:
You want to call some cleanup operation for objects (e.g. disconnects
from the DB, closing/deleting of files, etc.),
but you only if you know that you (that is for instance a generic object
factory/cache) are the last user of the object.
How can you know that you are the last user in a deeply nested call
stack, if the reference counter has not been increased?
You just can't - and you end up doing the cleanup before the methods
invoked on the object actually have finished their work.
 
Bodo.
 
Bodo Bergmann
Senior Software Engineer
OpenROAD Worldwide Development
Ingres Corp.
 

________________________________

From: Peter van Bennekom [mailto:Peter.vanBennekom at infor.com] 
Sent: Wednesday, November 14, 2007 1:38 PM
To: International OpenROAD Users
Subject: RE: [Openroad-users] Question about the value and
useof.InstanceReferences



Bodo,

 

My code only holds one reference - the fact that there is a system
variable called curObject does not constitute a reference increase -
besides it is in the object itself - I do not expect a reference
increase inside of itself (including subclasses)...

 

It would be nice to know if this attribute is used by anyone else in
what way.

 

 

Oops

METHOD showIR() =

Begin

          Curmethod.trace( text = 'showIR: ' + varchar(
curObject.InstanceReferences ) );

          curObject.showMore();

End;

 

 

Peter van Bennekom | Sr. Principal Architect | Infor | office:
610-407-8113 | fax: 610-407-8027 | mailto:peter.vanbennekom at infor.com

________________________________

From: openroad-users-bounces at peerlessit.com
[mailto:openroad-users-bounces at peerlessit.com] On Behalf Of Bodo
Bergmann
Sent: Wednesday, November 14, 2007 4:19 PM
To: International OpenROAD Users
Subject: Re: [Openroad-users] Question about the value and
useof.InstanceReferences

 

Peter,

 

why do you think that the reference count should be 1 ?

There are (at least) 2 references to the object when you are within your
showIR() method:

1.	the one from your variable ir_object in the calling procedure
ir_test 
2.	CurObject system variable in the method scope points to the same
object 

So, IMO the output is correct.

 

BTW:

The output and the source you provided don't match:

There is no invocation of ShowMore(), but there is an output for it.

 

Regards,

Bodo.

 

Bodo Bergmann

Senior Software Engineer

OpenROAD Worldwide Development

Ingres Corp.

 

 

________________________________

From: openroad-users-bounces at peerlessit.com
[mailto:openroad-users-bounces at peerlessit.com] On Behalf Of Peter van
Bennekom
Sent: Wednesday, November 14, 2007 8:51 AM
To: International OpenROAD Users
Subject: [Openroad-users] Question about the value and use
of.InstanceReferences

Folks,

 

I have noticed that this attribute reflects the number of instances
pointing to this object at runtime - not only does it hold the number of
references in the code but it also reflects when OpenROAD points to it.
Example:

 

PROCEDURE ir_test() =

Declare

          ir_object = ir_class;

EndDeclare

Begin

          Curprocedure.trace( text = 'proc before call: ' + varchar(
ir_object.InstanceReferences ) );

          Ir_object.showIR();

          Curprocedure.trace( text = 'proc after call: ' + varchar(
ir_object.InstanceReferences ) );

End;

 

Ir_class is userclass with two methods:

METHOD showIR() =

Begin

          Curmethod.trace( text = 'showIR: ' + varchar(
curObject.InstanceReferences ) );

End;

 

METHOD showMore() =

Begin

          Curmethod.trace( text = 'showMore: ' + varchar(
curObject.InstanceReferences ) );

End;

 

Output is as follows:

proc before call: 1

showIR: 2

showMore: 3

proc after call: 1

 

One can argue about the value of this kind of increment and decrement.
If one would like to implement a concept of freeing memory when object
is not needed anymore (circular references i.e. but also NULLing pointer
from self - we have found that sometimes when you do not null pointers
when not needed anymore memory is still claimed) based on the
instanceReferences attribute one would find out this is impossible.  One
would like to see how many references the code has (1 in this little
example) so implementing above mentioned concept can be done.

 

My questions to the group are: are you using this attribute, if so: how
are you using it and do you have to jump through hoops to get what you
want?  If you are consciously not using it what kept you from using it?

 

Thanks,

Peter

Peter van Bennekom | Sr. Principal Architect | Infor | office:
610-407-8113 | fax: 610-407-8027 | mailto:peter.vanbennekom at infor.com

  <http://www.infor.com/> 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.peerlessit.com/pipermail/openroad-users/attachments/20071114/2dc6117c/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 2926 bytes
Desc: image001.gif
Url : http://www.peerlessit.com/pipermail/openroad-users/attachments/20071114/2dc6117c/attachment-0001.gif 


More information about the Openroad-users mailing list