Jump to content

Memory lifetime for class VIs.


Recommended Posts

I have a class that stores some data in functional globals (FGs): this is essentially data that might be considered class/static data in other languages. The FGs are privately owned by the class.

I'm worried about the lifetime of the VIs though, as ultimately I'm not familiar with how classes are handled and I'm dealing with a bunch of dynamically loaded VIs. If I'm not mistaken, a VI can unload from memory if the "owning" VI unloads, even if it's referenced elsewhere, and is one of the things you need to keep in mind when dealing with FGs. Do I run the same risks when dealing with class methods? That is, does the VI being owned by a class change the behavior at all? Can a class partially unload if the VI that brought the VIs into memory unloads? Heck, can an entire class unload if the referencing VI dies?

-michael

Link to comment

QUOTE (MJE @ Mar 10 2009, 12:56 PM)

If I'm not mistaken, a VI can unload from memory if the "owning" VI unloads, even if it's referenced elsewhere,
This is wrong. A VI stays in memory as long as there are any callers of it or there are open VI references to it. You're thinking of the VI *reference* which is not the same as the VI itself. A VI reference goes stale as soon as the VI that opened that reference stops running, and when it goes stale, if it was the last reference, then the VI can leave memory. But if the VI is referenced elsewhere, the VI will stay in memory.

QUOTE

Do I run the same risks when dealing with class methods? That is, does the VI being owned by a class change the behavior at all?

A class loads all of its member VIs into memory when it itself loads. After that, things get complicated, but I'm going to gloss over a whole bunch of generally not applicable situations and say "and the VIs stay around until the class leaves memory, which is after the class is no longer referenced and the last piece of class data has been deallocated." Essentially, the answer is: yes, things are different and simpler, because the member VIs load with the class and there's no way to unload the class as long as your app is still running.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.