NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to deallocate or null a .NET object reference at the end of a sequence

I am creating a .NET object using assemblies and currently I am saving it to the file globals in order to be used for the rest of the sequence.  I am finding that this reference is staying open and causing a communication problem when I rerun the step.  What can I do to null/delete the object after the sequence executes?

0 Kudos
Message 1 of 5
(5,015 Views)

In TestStand if you set an object reference to Nothing then it is similar so:

 

Locals.MyObjRef = Nothing

 

Nothing is a reserved word.

 

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 2 of 5
(5,013 Views)

You can set the reference variable to Nothing in an expression, but that doesn't necessarily solve your problem because .NET is a garbage collected language. .NET objects aren't immediately deleted when the last reference to them goes away. The feature of .NET used to more deterministically do cleanup is call IDispose. If your .NET object supports disposing then you should check the "Dispose" checkbox next to the parameter in the .NET adapter which you use to store the object in a TestStand variable. If you do that, then when the teststand variable is set to Nothing, TestStand will call Dispose on the .NET object, which, if the .NET object implements a Dispose method that does the cleanup you require, will resolve the issue.

 

Hope this helps.
-Doug

0 Kudos
Message 3 of 5
(5,011 Views)

Let's say we have a subsequence X and in it, a .NET object is returned to Locals.Ref. Is it needed to do Locals.Ref = Nothing at the end of this subsequence for it to call Dispose? Or maybe ending the context of subsequence X will also call Dispose?

Michał Bieńkowski
CLA, CTA, CPI

  1. Did someone devote their time to help solve your problem? Appreciate it and give kudos.
  2. Problem solved? Accept as a solution so that others can find it faster in the future.
  3. Contribute to the development of TestStand by voting on the TestStand Idea Exchange.
0 Kudos
Message 4 of 5
(49 Views)

Based on this https://www.ni.com/docs/en-US/bundle/teststand/page/assigning-values-to-object-references.html

I guess it is automatically disposed.

Michał Bieńkowski
CLA, CTA, CPI

  1. Did someone devote their time to help solve your problem? Appreciate it and give kudos.
  2. Problem solved? Accept as a solution so that others can find it faster in the future.
  3. Contribute to the development of TestStand by voting on the TestStand Idea Exchange.
0 Kudos
Message 5 of 5
(19 Views)