February 2007

Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28      
Blog powered by TypePad

« Chaos and Order | Main | What is a Service Dog? »

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83424ed4953ef00d834bdfc2869e2

Listed below are links to weblogs that reference How to say goodbye to your Refnum:

Comments

Sebastian Dau

Hello,

nice documentation!

I asume that most of us already made our own experiences with that sort of LabVIEW - .NET issue.
In other words: I'd have expected to see this great explanation some months(year) earlier.

Is there an understandable reason for the fact that we have to close these unused refnums our own? At first I thougth that these handles are garbage collected when they become invalid (when the function that uses this refnum ends execution) as it happens in other .NET environments.

Thanks, Sebastian

Brian Tyler

First off - I'm glad that this was helpful. If you have other areas that you'd like to see covered, please let me know.

Second, the reason that you need to close the refnums is that LabVIEW is not a garbage collection (GC) system.

To ensure that the .NET object stays around as long as you'll need it, we tell the .NET GC that we're an external reference (via a GCHandle) and thus the object won't be GC'ed until we release that reference.

Again, LabVIEW does track all of these references, but the only time we know it's safe to release them is when all the VI stop executing - and that means long running applications need to be careful.

Hope that helps clear it up.

Sebastian Dau

Thanks,Brian that sounds reasonable to me!

Matt Leonard

I just feel into about every error you listed (except the constructor/close one). I assumed closing any refnum would cause issues with .NET and GC, but the assumption was in the wrong direction.

I wanted to add one additional note for 7.1 users (this is fixed in 8+): If the refnum wired is branched anywhere, and the branch is not closed, the the ref (and hance the GCHandle) sticks around. All branches of refnum wires must be closed. In 8+ it seems that any usage of a closed refnum that was previously branched will through a 1172 exception. This seems to be the correct way to implement this. Unfortunately, my project is stuck on 7.1 and not upgrading. But thanks for this blog entry. Saved me a lot of time.

Matt Leonard

Typo: I meant "fell" into every error.

Brian Tyler

I'm glad the post is coming in handy. I know when I started in LabVIEW near the end of LV 8's development, I was confused myself on the rules and basically discovered the above "facts" by code review and a debugger. :)

I haven't gone back to look at LV 7 code, but I'm surprised to hear what you said about the branching wire. I don't believe that is the case - branching the wire creates a copy of the data on the wire - the refnum itself - but it shouldn't create a new refnum. Do you have a test VI that shows this behavior? If so, please mail it to me.

Shailesh

I am very new in using Labview. I made .Net program and I want to use the methods from DLL generated by .Net framework in labview. I tried to follow the way given on NI website but I am not able to see any method. Can anybody please send me small .Net program which has one public method that I can see and use in labview environment.

Thank you

Brian Tyler

The easiest thing is to try to call something from the .NET framework itself. For example, you can drop down a constructor node and then scroll down to the System assembly. Then select the System.UriBuilder class. This has several nice methods and properties that build up URLs or display their parts. I like it as a beginners point since it's almost all simple strings.

Wiebe

Hi,

In response to a discusion on the NI forum (http://forums.ni.com/ni/board/message?board.id=170&message.id=324051&requireLogin=False ), I just like to let everybody know that everything told here also applies to ActiveX references.

I didn't know that references without a wire don't need to be closed...

Thanks,

Wiebe.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment