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.
Method Public test(a as char):
DEF VAR x AS EncodedPasswd NO-UNDO.
x = New EncodedPasswd().
Method Public test2(a as char):
Return New EncodedPasswd().
Thanks & Regards,
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.
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.
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...