‎2006 Jan 30 8:48 AM
Hi,
I have a class in ABAP. My constructor is;
method CONSTRUCTOR.
...
CREATE OBJECT X_APP_EXCEL 'excel.application'.
...
endmethod.
I want to free X_APP_EXCEL object in destructor. And I wrote;
method DESTRUCTOR.
FREE OBJECT X_APP_EXCEL.
endmethod.
But, I am getting an error as;
"Within a destructor method, you can only use the system-call c-destructor." What is this? How can I free my object?
Thanks.
‎2006 Jan 30 9:00 AM
when you created the method (destructor) its self the system would warn you that only c-destructor is supported.
its generally implemented using method FREE.
Regards
Raja
‎2006 Jan 30 8:57 AM
Hi,
if you see the standard classes there you can see only clear , and refresh.
so i think you can use clear and refresh to destroy.
don't use free.
for reference see the class method <b>cl_gui_alv_grid</b> 's <b>FREE</b> method. this is a destructor.
in side destructor you use clear and refresh that will work.
regards
vijay
‎2006 Jan 30 9:00 AM
when you created the method (destructor) its self the system would warn you that only c-destructor is supported.
its generally implemented using method FREE.
Regards
Raja
‎2006 Jan 30 9:09 AM
I can not write anything in destructor. When I write refresh and clear commands, the same error occured, and my X_APP_EXCEL is an ole object. I have to free this object. But I do not know how can I do? And what is c-destructor?
‎2006 Jan 30 9:12 AM
hi,
better change the name of the method and see .
change the name from destructor to free or some thing else.
regards
vijay
‎2006 Jan 30 9:16 AM
Yes that is alternative for solution. But, this class will be used by another users. Maybe at the end of they will not call the FREE method for free my X_APP_EXCEL. In this case, this is not good for object programming.
‎2006 Jan 30 9:19 AM
Hi,
you should ask them to use the FREE method. to free the object.
regards
vijay
‎2006 Jan 30 9:36 AM
Thanks
But, I want to ask that, why there is a destructor method in ABAP? When and why this method will be used? In another languages such as java, I am declaring destuctor method to free of class's resources. Is there any different concept for ABAP's destructor?
Thanks.
‎2006 Jan 30 9:42 AM
There are no destructors in ABAP. Read note 168703 to get details and explanations on this topic. In Java there is also no destructor only method 'Finalize' but you don't have guarantee when it will be called.
DESTRUCTOR statement in ABAP is for SAP intrnal use and can call kernel routines written in C.
From note 168703:
"<b>In light of all these problems, the designers of ABAP Objects decided no not provide an ABAP Destructor at this time. Instead, there is a provision for a 'C-destructor' that can however only be used by SAP kernel developers.</b>"
Message was edited by: Tomasz Mackowski
Message was edited by: Tomasz Mackowski
‎2006 Jan 30 9:44 AM
Hi,
i have no idea where it is used ABAP,
may be it is for internal use.
that is the reason it is throwing errors.,
regards
vijay
‎2006 Jan 30 9:48 AM
Hi All,
Well I tried finding some documentation on this , but in vain .... so it doesnt seems this a reserved SAP method.
but it seems that the method destructor does not allow abap calls inside itself.
that means u can only use direct system call(kernel) to free memory.
As recommended by Vijay changing the name of method should solve your problem.
regards,
Sumeet Mishra
‎2006 Jan 30 9:56 AM
Hi,
Well just to add to your understanding u can look for documentation on GARBAGE COLLECTOR.
ABAP uses GARBAGE COLLECTOR TO actually delete all object related resources.
During the FREE OBJECT command only the reference is lost , the memory is cleared only when the Garbage collector comes into picture.
regards,
Sumeet Mishra
‎2006 Jan 30 10:04 AM
Garbage Collector is used for managing ABAP Object objects, and FREE OBJECT is used to release OLE object referenced from ABAP code.
So I think you cannot guarantee freeing of Excel OLE object in your application after "destruction". You have two choices:
- free this object by yourself , but you must find a goood place where to do it, or
- leave this responsibility to clients of your class giving them some kind of 'free' or 'release' method which will call FREE OBJECT