LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory leak?

CVI examples often show multiple panels being loaded in main() like this:

if ((mainPanel = LoadPanel (0, "FPEditor.uir", MAINPANEL)) < 0)
return -1;
if ((newFPPanel = LoadPanel (0, "FPEditor.uir", NEWFP)) < 0)
return -1;

If the first call to LoadPanel succeeds but the second one fails and main()
returns
without calling DiscardPanel(mainPanel), isn't this causing a memory leak?

Nick J
0 Kudos
Message 1 of 2
(2,893 Views)
Hello

You are correct. There is potencial for memory leaks which is why calling DiscardPanel is always essentail. Its responsible for cleaning up resources used by the panel ( activex, GDI etc... ). CVI calls DiscardPanel for you, but its not a good idea to depend on this, especially for complicated cases ( multiple panels in multiple threads ). In the case of this example, since all the panels are loaded in the same thread, you wont see any leaks since CVI is automatically calling DiscardPanel for you.

But better safe than sorry.

I hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 2
(2,893 Views)