NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

free teststand objects in .NET

I’ve noticed that the C# RTOI NI has released has a call to GC.Collect() in an idle event callback even though Microsoft recommends against doing this. I suspect that this is the only way for TestStand to free objects (ie. propertyObject) in the .NET environment.

 

In the sequence editor I get a warning message regarding objects not released correctly (See attached file).  These are COM objects that do not derive from Idisposable so this no dispose method available.

 

1.) Is there a method other that calling GC.Collect() to free TestStand Objects from the .NET environment?

 

2.) Are there any improvements planned to correct this situation in future TestStand versions?

 

It seems as though it is possible to set the local object reference to nothing in TestStand after a call to a .NET assembly which seems to free up objects from that call.

 

3.) Does this actually free object references in TestStand?

 

4.) When the local object reference from a .NET call goes out of scope it doesn’t appear as though the TestStand objects get released  correctly. So, what is the difference in setting a TestStand local variable representing a .Net object reference to nothing vs. simply allowing the variable to go out of scope?

 

Thanks,

Steve

0 Kudos
Message 1 of 5
(3,575 Views)
Steve,

1) I believe the reason this is required is due to how the COM objects are handled, but I will have to verify with our R&D team.

2) I will contact our R&D team, though if I am correct with how the COM objects are handled, it may not be possible.

3) Yes, this should be freeing that object

4) The object reference in a local variable actually wraps the .NET object into a COM object. Therefore, it never sees the variable go out of scope through the ActiveX.

Brandon Vasquez | Software Engineer | Integration Services | National Instruments
0 Kudos
Message 2 of 5
(3,553 Views)
Here's some information I was able find out from R&D.

1) For these COM objects, this is the only way to dispose of them.

2) Since this is the only way, there is no possibility of this changing in the future.

3) Yes

4) You should not have to set it to nothing because once it goes out of scope, it will set itself to Nothing and garbage collection will take care of it. If you would like to release it sooner than this, you would then set it to nothing.

Brandon Vasquez | Software Engineer | Integration Services | National Instruments
0 Kudos
Message 3 of 5
(3,526 Views)

 

Here is what I used to release sequence file objects in C#

 

private void ReleaseSequenceFile( SequenceFile SeqFile )

{

bool released = false;

while( !released )

released = _engine.ReleaseSequenceFileEx( SeqFile, 0x1 );

System.Runtime.InteropServices.

Marshal.ReleaseComObject( SeqFile );

SeqFile =

null;

}

 

Here is what I did for PropetyObjects:

The oParameter was a NI PropertyObject reference.

System.Runtime.InteropServices.

Marshal.ReleaseComObject( oParameter );

oParameter =

null;

Now, this was code I wrote a year or so ago...But, I also call GC collect.  Even though MSFT discourages the use of forcing a GC, I feel it is necessary and not signifcantly taxing the resources for me to accomplish the release.

 

The Only Easy Day Was Yesterday.
Message 4 of 5
(3,485 Views)

Toedwy:

That worked great.

Thanks, 

Steve

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