Forum Discussion

idane's avatar
13 years ago

C# Object still alive after test is completed causing TestComplete to hang

I seem to be having an odd problem. I have a C# object loaded via the CLR bridge which, once created, is not destroyed once the test is completed (I use debugview to monitor it, and it is still very much active once the test is completed).



I tried checking if the project variable it is assigned to != null when the test starts and only to call the constructor in case the variable ==null , but it is always null when starting a test even though the object is still active).



This is even more troublesome, as once the constructor is called upon from testcomplete, testcomplete simply freezes and has to be forcefully killed.



Can anyone please help me out or point me in the right direction as to how to resolve this issue?



Also, I noticed that TC hangs if there are any new incoming logs from the C# object while handling a log message event. Is there any way to handle this issue so that testcomplete does not hang?



Thanks in advance,

IdanE

1 Reply

  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Idan,


    I tried checking if the project variable it is assigned to != null when the test starts and only to call the constructor in case the variable ==null , but it is always null when starting a test even though the object is still active).


    Project variables that store object references are not persistent. That is, they don't store their values between test runs.


    This is even more troublesome, as once the constructor is called upon from testcomplete, testcomplete simply freezes and has to be forcefully killed.


    Does this occur when you call the object constructor for the second time? If it does, perhaps, this happens due to some specific behavior of the object's constructor: it does not respond to the call, and this causes TestComplete to fail.


    Currently, it's difficult to understand what is going wrong as I don't know the code of your C# object and the way the object is used. TestComplete loads assemblies when it accesses the CLR Bridge in your project for the first time. The assemblies remain loaded until the project is closed or changed. So, most likely, there are references to your object after the test run is over. To clean the references, I'd suggest doing this:


    * At the end of the test run, remove all the references to the object in your .NET code (that is, clear the object that can hold links to your object).

    * Call the following statements:




    // Assign null to the project variable that stores the object reference

    ProjectVariable = null;


    // Call JScript's garbage collector.

    // This is needed, because null assignment does not release the object reference immediately

    CollectGarbage();


    // Call .NET's garbage collector

    dotNET.System.GC.Collect();


    Hope this helps.