Figure 55 shows possible problems associated with the misuse of heap storage.
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
*-----------------------------------------------------------------*
* Heap Storage Misuse *
*-----------------------------------------------------------------*
D Fld1 S 25A BASED(Ptr1)
D Ptr1 S *
/FREE
Ptr1 = %ALLOC(25);
DEALLOC Ptr1;
// After this point, Fld1 should not be accessed since the
// basing pointer Ptr1 no longer points to allocated storage.
SomePgm();
// During the previous call to 'SomePgm', several storage allocations
// may have been done. In any case, it is extremely dangerous to
// make the following assignment, since 25 bytes of storage will
// be filled with 'a'. It is impossible to know what that storage
// is currently being used for.
Fld1 = *ALL'a';
/END-FREE
Similarly, errors can occur in the following cases:
The storage will not be freed until the activation group ends.