Application Development and Automation 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: 
Read only

Dynamic Memory

Former Member
0 Likes
1,137

Hello,

I was reading up the field symbols(FS) and data references(DR) in the ABAP help documents and i have a doubt.

When you can use data references to allocate memory dynamically how can or rather what happens to this memory when you have done both of the following

1) Used the CLEAR statement on the DR &

2) Used the UNASSIGN statement on the FS into which the

DR was de referenced.

I understand the DR will stop pointing to anything but then what really happens to the memory it was pointing to. Questions

1) Is it deallocated ?

2) Is it left dangling i.e. will it remain there until

the program is ended ?

I am looking at deallocating this memory completely. Is this possible?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
891

Hi Gerson,

The memory will be re-claimed by the ABAP Garbage Collector.

Regards,

Anand Mandalika.

6 REPLIES 6
Read only

Former Member
0 Likes
892

Hi Gerson,

The memory will be re-claimed by the ABAP Garbage Collector.

Regards,

Anand Mandalika.

Read only

0 Likes
891

Appreciate that Anand.

When does garbage collection happen in the ABAP runtime. Is it during the program execution itself or after the program has terminated.

I just read about garbage collection with respect to instances of a classes and it is the most ideal thing. But does the same principle apply to say internal tables or structures if data references had been used to create them.

Message was edited by: Gerson D'lima

Read only

0 Likes
891

Hi,

Garbage collection. An object is in use as long as there is at least one reference pointing to it. When there are no more references pointing to an object, the memory space occupied by that object can be released. ABAP Objects provides a garbage collector, which ensures that the memory is collected automatically.

Read only

0 Likes
891

Does this work the same way for non class related objects that is say a data field created using the CREATE DATA statement?

Read only

0 Likes
891

Hi,

I hope so.

Check this.

Object Lifetime

An object exists for as long as it is being used in the program. An object is in use by a program for as long as at least one reference points to it, or at least one method of the object is registered as an event handler.

As soon as there are no more references to an object, and so long as none of its methods are registered as event handlers, it is deleted by the automatic memory management (garbage collection). The ID of the object then becomes free, and can be used by a new object.

Read only

0 Likes
891

Hi Gerson,

To answer your question, garbage collector will run to clean up dangling references to DATA as well.

I would like to add something more in this context -

It is natural to associate garbage collection with Objects, since that is what we see in other languages (Java, for example).

In ABAP, if you have noticed, we can have references to data as well as objects. Look at the following variant of the DATA statement -

DATA OREF TYPE REF TO OBJECT.

The above statement can be used to create an object whose type (i.e., a class) is not known until runtime.

So, any dangling reference will be considered by the garbage collector, whether it is to DATA or OBJECT.

Further, if the memory is reclaimed after the program execution, it is no longer termed as <i>garbage collection</i>. The idea is to make a program run in as little memory as required.

Regards,

Anand Mandalika.