LabView will leak memory unless you close every object reference in the ActiveX call. This includes both
object references that you explicitly opened with the "Automation Open" call and those that were opened
implicitly by reading a property or calling a method that returns an object reference. Every refnum wire
that you see must have an explicit close function. (You will, therefore, have many more "close" operations
than "open" operations.)
This behavior is different from languages like Visual Basic, where objects are automatically garbage
collected when they go out of scope or when the reference count goes to zero (usually when the parent
object is released.)
If you don't close the reference, LabView will not do it for you. Since the child objects become completely
unreachable after you release the parent, I don't think this is a particularly good implementation, but you
should be able to clear up your memory leak by assiduously closing every object reference.
I've attached a VI (LV 7.1) to demonstrate how an unclosed reference causes a leak. The attached VI parses
some XML using Microsoft's MSXML6 library. You may need to download MSXML6 from:
By default I close the XMLDOMMode Object after using it. Click the "leak" checkbox to retain the object. LabView will
not release it when the parent object is released, or even when the VI itself is removed from memory (!). Run it like this
in a loop and you can burn 90 MB of memory in no time.
Notes when testing for memory leaks:
* Always start with a fresh launch of LabView.
* Always wait for LabView to finish background loads of palettes, etc. These look JUST LIKE a memory leak.
* Use the Task Manager to monitor cpu, memory usage. (You'll see when LabView has finished loading; cpu -> 0).
* Expect memory usage to jump when the ActiveX component is first called. You won't get all of this
memory back, even if you remove the VI from memory. Whether this is a result of caching for performance
or a bug, I do not know. In practice, the one-time memory usage is not a big deal.
* The task manager's memory usage resolution is fairly coarse, so you'll need to call whatever you
are doing in a loop to magnify the effects of the leak.
* After the first call, LabView.exe's memory usage should be constant. If it grows every time you click the "Test"
button, you still have a memory leak. Review your code for missing close operations.
-Rob Calhoun
Thanks to Jason Dunham for helping to track this down.