Garbage collection - How Can I know the number of references

Posted by ecsousa on 11-Sep-2014 16:09

Hello,

May i get the number of references for  one object?  Is it possible? 

Can i know how many references each object has in the garbage colletion control?

Thank you,



All Replies

Posted by Mike Fechner on 11-Sep-2014 16:14

Why do you need to know this?
 
There is no simple solution. But if you share more about your use case there might be a solution.

Posted by ecsousa on 11-Sep-2014 16:27

First, sorry about my english mistakes...i don´t know how to write in english very well...

I need to make a function like a Handle function.....for objects of a particular class ...

example:

def var x as handle no-undo.

def var y as handle no-undo.

def var str as char no-undo.

str = string(x).

y = handle(str).

So.. i have my class ellen...

def var x as ellen no-undo.

def var y as ellen no-undo.

def var str as char no-undo.

str = x:tostring().

How can I get the object from str??

I made the next code....but it is very expansive ( time) when i have many objects.

Define Variable myObject As Char no-undo.

define variable loop as Progress.Lang.Object no-undo.

Assign myObject = "1234".

loop = Session:First-object.

Do While valid-object(loop) :

    if (loop:tostring() = myObject) then Do:

         MESSAGE "Found!!!" VIEW-AS ALERT-BOX INFO BUTTONS OK.

         Leave.

    End.

   loop = loop:Next-sibling.

End.

As alternative solution......I am saving the objects in a temp table..   but the garbage colletion never deletes my object because they have an reference in my temp-table.......... and I dont have when i should delete the record.....  :/

Posted by Tim Kuehn on 11-Sep-2014 16:40

Again - what problem are you trying to solve?

Posted by ecsousa on 11-Sep-2014 16:44

I need to make a function like a Handle function.....for objects of a particular class.

Posted by Mike Fechner on 11-Sep-2014 16:45

That bit of sample code you provided loops through all objects and checks for a common criteria.
 
How many objects are you looping through? 1000’s or 100.000’s? How difficult is it to compute the result of the ToString() method (assuming you have overridden it).
 
Just looking though all objects is typically not that expensive. Which runtimes do you experience?
 
 
But that would not be a solution to your initial enquiry about the number of objects referencing another object.
 
 
Von: ecsousa [mailto:bounce-ecsousa@community.progress.com]
Gesendet: Donnerstag, 11. September 2014 23:29
An: TU.OE.General@community.progress.com
Betreff: RE: [Technical Users - OE General] Garbage collection - How Can I know the number of references to an object?
 
Reply by ecsousa

First, sorry about my english mistakes...i don´t know how to write in english very well...

I need to make a function like a Handle function.....for objects of a particular class ...

example:

def var x as handle no-undo.

def var y as handle no-undo.

def var str as char no-undo.

str = string(x).

y = handle(str).

So.. i have my class ellen...

def var x as ellen no-undo.

def var y as ellen no-undo.

def var str as char no-undo.

str = x:tostring().

How can I get the object from str??

I made the next code....but it is very expansive ( time) when i have many objects.

Define Variable myObject As Char no-undo.

define variable loop as Progress.Lang.Object no-undo.

Assign myObject = "1234".

loop = Session:First-object.

Do While valid-object(loop) :

    if (loop:tostring() = myObject) then Do:

         MESSAGE "Found!!!" VIEW-AS ALERT-BOX INFO BUTTONS OK.

         Leave.

    End.

   loop = loop:Next-sibling.

End.

As alternative solution......I am saving the objects in a temp table..   but the garbage colletion never deletes my object because they have an reference in my temp-table.......... and I dont have when i should delete the record.....  :/

Stop receiving emails on this subject.

Flag this post as spam/abuse.

Posted by Tim Kuehn on 11-Sep-2014 16:48

Each reference to an object is a "handle" or pointer to that object. What it sounds like is you're looking to create a collection of objects that you want to do similar things to.

Posted by Thomas Mercer-Hursh on 11-Sep-2014 16:49

Are you trying to write your own object manager instead of relying on garbage collection?   If so, then each request for an object you would need to keep your own count and then decrement that count when the object is no longer used.  I.e., do the same thing the GC is doing for you.

Posted by Tim Kuehn on 11-Sep-2014 16:54

If the OP's using an older version of Progress, she may not have garbage collection in the language hence the need to count references...

Posted by Mike Fechner on 11-Sep-2014 16:59

If the OP's using an older version of Progress, she may not have a garbage collection hence the need to count references...

Good point. But no one should do new development on 10.1x anymore!

Posted by Thomas Mercer-Hursh on 11-Sep-2014 17:01

If that is the requirement, Tim, the OP could probably adapt the ideas here www.oehive.org/PseudoSingleton

Posted by Tim Kuehn on 11-Sep-2014 17:04

[quote user="Mike Fechner"]

But no one should do new development on 10.1x anymore!

[/quote]

Some developers don't have a choice in the matter....

Posted by ecsousa on 11-Sep-2014 17:19

Thank you ........ do you think this is the best solution?

I did the same..... and  "solve" my problem except because too time-consuming

Define Variable myObject As Char no-undo.

define variable loop as Progress.Lang.Object no-undo.

Assign myObject = "1234".

loop = Session:First-object.

Do While valid-object(loop) :

   if (loop:tostring() = myObject) then Do:

        MESSAGE "Found!!!" VIEW-AS ALERT-BOX INFO BUTTONS OK.

        Leave.

   End.

  loop = loop:Next-sibling.

End.

Posted by Peter Judge on 12-Sep-2014 07:51

If you follow your approach, I would change a few things - especially the data type you store the object reference in. Do not use ToSTring() for this stuff, since you cannot know what value is returned. It might have a reference in it - per the default - but there are times when it won't.

define variable myObject as INTEGER.

Assign myObject = 1234.

loop = Session:First-object.

Do While valid-object(loop) :
   if INTEGER(loop) eq myObject) then Do:
        MESSAGE "Found!!!" VIEW-AS ALERT-BOX INFO BUTTONS OK.
        Leave.
   End.

  loop = loop:Next-sibling.

End.


Posted by ecsousa on 12-Sep-2014 15:09

Hi Peter,

Thank you for your advices.

It was much better than using ToString, but, even so, if I have a set of 1000 objects and realize 1000 searches this way the time required is extremely high  =(

There is no function that returns the object from reference, is there?  another solution besides using loop...

This thread is closed