Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to Delete an Object in OABAP?

prabukannans
Participant
0 Kudos

Hai,

When we have created an Object in OOABAP, how to delete the object because of reusability?

7 REPLIES 7

maheshpalavalli
Active Contributor

Delete an object means, you wnat to clear it using FREE: OBJ1? or do you mean something else?

FredericGirod
Active Contributor

Object means nothing, just the usage of Class/Interface in programming.

So, there is:

- Class: those you can create in SE24

- Instance: When you use these class using code like my_instance = new my_class( ).

Delete a class, is suppress the class in SE24.

For Instance, it is more complex. You cannot really delete an instance, you just delete the reference to this instance.

my_instance = new my_class( ).

my_instance is a reference to the instance created based on my_class.

so if you want to have my_instance link to a new instance, you could use FREE.

But ! it will not delete the first instance, just delete the reference to this first instance.

Hi, prabukannan

Use CLEAR <OBJ_NAME>.

Thank you

raymond_giuseppi
Active Contributor

You wont directly delete an instance, it will be deleted by garbage collector once its last reference and every event handler is removed by an explicit clear (or free) statement or an implicit end of lifetime.

NB: You could eventually use method CL_ABAP_MEMORY_UTILITIES=>DO_GARBAGE_COLLECTION, but should not usually be required.

0 Kudos

I saw this one, but I never try

METHOD destructor.    
  SYSTEM-CALL c-destructor 'name' USING attr1 attr2 ...  
ENDMETHOD.

0 Kudos

More information on Abap handling of destructor methods can be found in 168703 - Destructors in ABAP Objects - ... 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...

prabukannans
Participant
0 Kudos

Like It should be deleted permanently. we cannot use the object in some other place.