Jump to content

Using LabVIEW Clusters with .NET Invoke Nodes


Recommended Posts

I was writing a long summary of what I was trying to do, when I realized it might be best to start off with a simple question:

 

Is it possible to pass a LabVIEW cluster to/from a .NET invoke node?  

 

I have complete control over both the .NET and LV code, but I have not been able to find a way to do this.

Link to comment

Thanks, ned.  That is what I have been doing up to this point.  I was just hoping there was a way I could put more of the .NET object construction and manipulation inside my C# code.  I'm fighting some nasty memory leaks in this code right now.  When I run it completely in C#, memory usage is flat.  When I run it in LabVIEW with C# .NET assemblies, I see an increase.  I have sprinkled close reference vi's throughout the code, wherever it doesn't break things, and it seems to help, but still gaining memory.  Is there a recommended way/time to close .NET references that are used as structs?

Link to comment

You should close references to all .NET objects when you're done using them. This includes objects that you didn't explicitly open in LabVIEW but are returned from .NET methods. Close references in the reverse order from opening them. If you call a method on an object A that returns object B, close the reference to object B before closing A.

Link to comment

A fun little experiment I'll do is write some code, and then if I'm unsure if something needs to be closed I'll throw it into a while loop (or use the continuous run for the first time that year) and monitor memory usage.  If it goes up, then I'm not closing everything, if it is steady, then all references that need to be closed, are.

Link to comment

OK, so let's say I have a .NET assembly that I use frequently throughout my application.  I call the constructor in my initialization code, use the same object to do whatever function throughout the code, and I close the reference in my shutdown code.  Sound good so far?

 

Reading seems pretty straightforward, as I can just close the .NET object that I get from the property/invoke node after I'm done turning it into a cluster.

 

So then I want to write a cluster/struct to that .NET assembly using a property or invoke node.  Is it better to construct->populate->write->close this struct object every time I need to do this, or to keep re-using one struct object every time I write (which can be as often as 100-200ms, depending on state), constructing and closing it at the same time as the main .NET assembly?

 

Finally, some strange behavior (at least to me) seems to happen when calling a .NET method that takes a "ref" argument.  This appears in LV as an invoke node with both an input and output terminal for the same argument.  I would expect this to return the same reference to the .NET object on the output terminal as was passed to it on the input terminal, but this is not what happens.  Instead you appear get a new copy of the reference (with a new refnum value if you probe it) on the output terminal.  So you need to close both the reference you passed into the invoke node, and the reference that was returned.  Has anyone else encountered this?  Is this expected?

 

Another thought on this: does it make a difference whether I use a get/set invoke node or just access the property directly?

Edited by MikeC3
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.