Forum Discussion

RHoward's avatar
RHoward
New Contributor
13 years ago

Memory cleanup in scripts

I'm noticing that the memory usage of TestComplete is fairly consistent
with some of my scripts and grows constantly with others, so I probably
introduced a memory leak.  Does anyone have any information or advice about cleaning up objects or arrays when running scripts?  How much manual cleanup is needed for a script that will run through to completion dozens or hundreds of times in a row?  It seems like there is a garbage collect happening, but maybe I'm doing something that gets in the way like leaving pointers around.



I'm using JScript if that makes a difference, and the only tests I have problems with tend to have arrays, objects, and sometimes arrays of objects.
  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Ryan,


    As far as I know, the script engine cleans memory itself. In general, script writers should not perform any specific actions for that.

    There are several situations when the script engine cannot clean memory (for instance, if you allocate a long string within a function and use this function as an event handler). You can find more information in the Web. For example, I've found this --


    http://stackoverflow.com/questions/4324133/javascript-garbage-collection

    http://stackoverflow.com/questions/864516/what-is-javascript-garbage-collection

    http://blogs.msdn.com/b/ericlippert/archive/2003/09/17/53038.aspx


    To force the garbage collection from within your tests, try using the CollectGarbage() JScript function.


    Also, TestComplete may cause this issue. I cannot say why it is happening as the situation needs closer investigations. I'd suggest that you contact our Support Team and send them a test project demonstrating the issue and detailed steps to reproduce it. Guys will check the TestComplete behavior and fix errors, if any.

  • sastowe's avatar
    sastowe
    Super Contributor
    I am trying to recall if JScript is handled by the Microsoft Script Engine. I think it is. A matter of some debate back in my ASP days was this matter of garbage collection. If my memory serves, garbage collection within the Microsoft Script Engine is not execute when things go out of scope. There is a delay. You can manually clean up your objects at the end of the script by setting them equal to nothing.  YMMV. I would hate for you to go through the trouble of doing that everywhere only to find it does not help.