Handling OBJECT DELETION to avoid Memory Leakage

Posted by adhyani on 14-Feb-2018 05:01

Hi All,

I need your help in fixing some Methods which are causing memory leakage issue in our Application and hence the AppServer and Webspeed Server is getting hung on a regular basis.Can you please help us to know the correct way of handling the objects deletion in case of below type of Methods.

Type 1:

Method Public test(a as char):

   DEF VAR x AS EncodedPasswd NO-UNDO.

   x = New  EncodedPasswd().

   Return x.

End Method.

Type 2:

Method Public test2(a as char):

   Return New  EncodedPasswd().

End Method.

Thanks & Regards,

Ajay Dhyani,

All Replies

Posted by Kim Ward on 14-Feb-2018 05:22

I cannot see how or why either of those methods would cause a memory leak. It's all down to how you use what they provide you. You don't want to manually delete any objects at this point as you're returning it and wouldn't be able to make use of it if you deleted it. I believe we would need more information in order to help you.

I expect the problem is how you're handling the EncodedPasswd instance later on.

Posted by adhyani on 14-Feb-2018 05:44

Hi Kim,

The Cases I have mentioned is just a sample Methods types which are detecting as a cause of Memory Leakage when I am running a progress leak_check utility. This utility identifies any Dynamic Objects whose Object or reference has been created but never get deleted in a session. I found many Methods or Procedures where Object Handle were not deleted and which we can fix easily by either deleting them in Destrctor or Finally Method However my above two cases are the one where I am confused or don't know how to handle these kind of cases. I am not sure whether these types of Methods coming in my leak_check utility is causing the issue or not. Please advise.    

Thanks & Regards,

Ajay Dhyani,

Posted by Tim Kuehn on 14-Feb-2018 07:12

in both your examples you're returning the object to something, and that "something" is where you need to look next to see what they do with the objects. 

Posted by Lieven De Foor on 22-Feb-2018 07:46

As Kim and Tim said, there's nothing wrong with both methods, who are completely equivalent by the way.

It is the caller of those methods that keeps a reference to the returned object, causing the leak.

Either way, I would never explicitly delete objects. Just make sure any variable holding a reference is set to ? (or goes out of scope) to have the GC pick up the object for deletion...

This thread is closed