TD-18726: Memory leak in SalObjGetType

Report bugs and possible workarounds for ANSI TD versions
MarWestermann
Germany
Posts: 74
Joined: 06 Mar 2020, 15:35
Location: Oldenburg Germany

TD-18726: Memory leak in SalObjGetType

Post by MarWestermann » 01 Jun 2012, 15:25

Hi,

when I write the following code in TD 4.1 SP2:

Code: Select all

cMyClass: myClass
Number: i

Set i = 1
While i <= 1000000
   Call SalObjGetType(new cMyClass)
   Set i = i +1
the memory is increasing permanently. There seams to be a leak in SalObjGetType

This behaviour also affects TD 6.1


regards, Marco

Jeff Luther

Re: TD-18726: Memory leak in SalObjGetType

Post by Jeff Luther » 01 Jun 2012, 23:59

What's the 'leak' ? That memory usage keeps growing as the Loop is run? You're defining a 'new' class instance each iteration and memory's being allocated for it. What would you expect TD to do as you instantiate 1 millions instances of cMyClass?

Since you don't provide a test case, I can't test this... so what happens if you drop the 'new cMyClass' from the call and pass 'myClass' as the parameter instead?

That above sentence was a hint: Why not provide us a small test case?

MarWestermann
Germany
Posts: 74
Joined: 06 Mar 2020, 15:35
Location: Oldenburg Germany

Re: TD-18726: Memory leak in SalObjGetType

Post by MarWestermann » 08 Jun 2012, 11:15

Hi Jeff,

I provided a testcase as attachement. you can see the following:

When you click on the button, the loop starts and makes 1,000,000 calls to the SalObjGetType function. The memory is inreasing permanently while the loop is running. This I don't expect cause the instances are not referenced so they should be freed immediately.

But they even didn't get freed after the loop ends and the focus is back to the gui. So when I click the button several times the memory increases as long as the application crashes with an out of memory error.

that is what I call a memory leak.

regards, Marco
You do not have the required permissions to view the files attached to this post.

jmcnamara

Re: TD-18726: Memory leak in SalObjGetType

Post by jmcnamara » 11 Jun 2012, 18:48

IMHO, it's a compiler issue - it shouldn't allow you to create an object without a reference name.

Change your code to this and I'll bet the memory leak goes away:

cMyClass: myClass
Number: i

Set i = 1
While i <= 1000000
Set myClass = new cMyClass
Call SalObjGetType(myClass)
Set i = i +1

MarWestermann
Germany
Posts: 74
Joined: 06 Mar 2020, 15:35
Location: Oldenburg Germany

Re: TD-18726: Memory leak in SalObjGetType

Post by MarWestermann » 22 Jun 2012, 10:08

Hi,

just tried that but it makes no difference.

Code: Select all

While nIdx <= 1000000
   Set cfMyClass = new cMyClass
   Call SalObjGetType(cfMyClass)
   Set nIdx = nIdx + 1

RainerE
Germany
Posts: 2278
Joined: 27 Apr 2021, 12:40
Location: Germany

Re: TD-18726: Memory leak in SalObjGetType

Post by RainerE » 25 Jun 2012, 09:34

Hi,

you are creating a new object each loop without releasing/destroying it.
cfMyClass only holds the reference to the new object.
If you overwrite the reference with the reference of another object,
you have two objects. Sadly you cannot destroy the first one because you do not have the reference to it anymore.

It's the same with SqlConnect(hSql).
If you call it twice for the same hSql Variable, you have two connections at SQLBase side from which you can only disconnect the last one:-(

Try:

Code: Select all

While nIdx <= 1000000
   ! create new instance of cMyClass
   Set cfMyClass = new cMyClass
   Call SalObjGetType(cfMyClass)
   ! release/destroy instance of cMyClass
   Set cfMyClass = OBJ_Null
   Set nIdx = nIdx + 1
Regards,
Rainer

fakie

Re: TD-18726: Memory leak in SalObjGetType

Post by fakie » 02 Dec 2012, 15:53

Hi,

it has nothing to do with object creation.
If I adapt the code like shown below, there are no new objects created, I'm just asking 1000000 times for the type of the object!!!!
And the memory usage is still increasing! So the bug has to be within the SalObjGetType() method!!!

Code: Select all

Function: runLoop
   Description:
   Returns
   Parameters
   Static Variables
   Local variables
      Number: nIdx
      FunctionalVar: cfMyClass
         Class: cMyClass
   Actions
      Set nIdx = 0
      While nIdx <= 1000000
         Call SalObjGetType(cfMyClass)
         Set nIdx = nIdx + 1
I've attatched the adopted test file so you can try it!


Kind regards

Patrick

Jeff Luther

Re: TD-18726: Memory leak in SalObjGetType

Post by Jeff Luther » 03 Dec 2012, 22:49

Patrick: I took the liberty of making 2 changes to your previous posting:

** I deleted your reference to EDIT: v6.1

I have back-ported your test case to v5.2 and have attached it here. Since this forum thread is a report for TD v5.2, I ran my 5.2 version and see memory usage increase while the loop is running, but reset once the appl. is finished.

BTW, your Loop is for one million iterations so I think it's important to keep in mind the difference between a test which demonstrates what I'll call a 'normal' issue vs. a 'stress test' issue. One million is pretty clearly on the stress end of the spectrum, but I will the techies internally about this.

TITLE: TD-18726 "SalObjGetType -- Memory usage climbs when this is called in a Loop. Exiting the Loop function does not deallocate memory and rerunning the loop continues memory usage"
You do not have the required permissions to view the files attached to this post.

Return to “Bug Reports (TD 4.2 and older)”

Who is online

Users browsing this forum: [Ccbot] and 4 guests