OE 11.0 , win32
given the following code
Class A
class temp.ClassA :
destructor ClassA():
message "GC delete".
end destructor.
method public temp.ClassA DoSomeThingElseFluent():
return this-object.
end method.
end class.
Class B
class temp.ClassB:
method public temp.ClassA GetMyClass():
return new temp.ClassA().
end method.
end class.
and this code
DEF VAR a AS temp.CLASSA NO-UNDO.
DEF VAR b AS temp.CLASSA NO-UNDO.
DEF VAR c AS temp.CLASSA NO-UNDO.
DEF VAR d AS temp.classB NO-UNDO.
d = NEW temp.classB().
a = d:GetMyClass().
b = a:DoSomeThingElseFluent().
c = d:GetMyClass():DoSomeThingElseFluent().
MESSAGE VALID-OBJECT(a) VALID-OBJECT(b) VALID-OBJECT(c) VIEW-AS ALERT-BOX.
why is it that I get
yes yes no ?
When you run the code, you get a "deleting" *before* the valid-object message, so an instance of class A is being deleted - and that instance is the chained call (c). However, in the case of "c", the DoSomeThingElseFluent method still returns a reference to classA which is stored in variable c (i.e. referenced) , so why is it getting GC'd ?
if you take class B out of the equation, ie run the following code
DEF VAR a AS temp.CLASSA NO-UNDO.
DEF VAR b AS temp.CLASSA NO-UNDO.
DEF VAR c AS temp.CLASSA NO-UNDO.
a = NEW temp.ClassA().
b = a:DoSomeThingElseFluent().
c = (NEW temp.ClassA()):DoSomeThingElseFluent().
MESSAGE VALID-OBJECT(a) VALID-OBJECT(b) VALID-OBJECT(c) VIEW-AS ALERT-BOX.
then everything works as expected , I get
yes yes yes
in this scenario, the line assigning c is doing the same task as the method in classB, but the outcome is very different.
Maybe I'm being stupid. But this doesn't seem to make sense ...
You may be running into bug OE00195481 (or a variant thereof). This is fixed for the next release, as far as I can tell, but I would contact TS anyway.
Incidentally, that bug fix should remove the need for extra parens around the NEW() in the latter case,.
c = (NEW temp.ClassA()):DoSomeThingElseFluent().
-- peter
Thanks Peter.
Is there any way of searching for open bugs ? Would have been very helpful to know that this bug existed before I spent hours trying to come up with a test case
Also, when you say "next release" do you mean 11.1 or 11.0 SP1 ?
Thanks!