NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
mcfrenzy36
Posts: 64
0 Kudos

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?

Active Participant
~jiggawax~
Posts: 1,028
0 Kudos

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

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

 

Locals.MyObjRef = Nothing

 

Nothing is a reserved word.

 

jigg
Test Development Engineer
L-3 Communications
Active Participant
dug9000
Posts: 1,509
0 Kudos

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

[ Edited ]

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

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page