Salesforce

DELETE OBJECT doesn't delete object which was created on the same HANDLE

« Go Back

Information

 
TitleDELETE OBJECT doesn't delete object which was created on the same HANDLE
URL NameDELETE-OBJECT-doesn-t-delete-object-which-was-created-on-the-same-HANDLE
Article Number000185865
EnvironmentProduct: OpenEdge
Version: 10.x, 11.x
OS: All supported platforms
Question/Problem Description
Application leaking memory.
Monitoring dynamic objects in the session shows that certain objects are not being deleted. (See also  How to check for leaked dynamic objects? and  How to detect ABL Memory Leaks with Dynamic Objects Logging).
Inspecting the ABL code shows that there are explicit DELETE OBJECT statements that use the same handles as the CREATE OBJECT statement where the leaking objects originate from.
Steps to Reproduce
Clarifying Information
Error Message
Defect Number
Enhancement Number
Cause
The HANDLE variable gets reassigned in the ABL code between the CREATE OBJECT and DELETE OBJECT statements, and the DELETE OBJECT statement tries to delete the object it currently points to.
Keep in mind a HANDLE variable is a reference to an object instance, not an object instance in itself.

For the "tranditional" built-on objects, this causes a memory leak. 
Class instances, both built-in classes and user-defined OOABL classes, will normally get cleaned by the garbage collector when references to it are lost.
Resolution
Modify the ABL code to ensure that:
- No excess objects are created by accident.
- Handles point to the correct object instance when calling DELETE OBJECT.
- Object instances are managed correctly. (Using widget-pools can help here)

Specific example(s):
Accidental create of object
DEFINE QUERY qCustomer FOR customer.
  
DEFINE VARIABLE cQueryString AS CHARACTER    NO-UNDO INITIAL "".
DEFINE VARIABLE hQuery       AS HANDLE       NO-UNDO.
DEFINE VARIABLE iCounter     AS INTEGER      NO-UNDO.

ASSIGN cQueryString = "for each customer no-lock".

DO iCounter = 1 TO 10:
   CREATE QUERY hQuery.
   hQuery = QUERY qCustomer:HANDLE. /* reassign happens here */
   hQuery:QUERY-PREPARE(cQueryString).
   hQuery:QUERY-OPEN().
   DELETE OBJECT hQuery.
END.
In this case the handle gets reassigned to a static query (which will get deleted when the defining procedure/class is removed, not when the DELETE OBJECT executes), so the dynamic query object never gets used or deleted.
As the code is written to re-use the static query object the CREATE QUERY and DELETE OBJECT statements are not needed at all, and can simply be removed from the code.
 
Workaround
Notes
Keyword Phrase
Last Modified Date11/20/2020 7:22 AM

Powered by