LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

run / quit user interface and memory clean up

Hi,

 

may be I simply miss a coffee, but here is my problem: I have a main function and a quit callback in a standard configuration, i.e. as follows:

 

int main ( int argc, char *argv [] )
{
...

    RunUserInterface ();
    DiscardMenuBar ( popup_menubar_handle );
    DiscardMenuBar ( menubar_handle );
    DiscardPanel ( panel_handle );
    return ( 0 );
}

int CVICALLBACK Quit ( int panel, int control, int event, void *callbackData, int eventData1, int eventData2 )

{
    if ( event == EVENT_COMMIT )
    {

        FreeDynamicMemory...

        FileCloseFiles ...

        QuitUserInterface ( 0 );

    }
    return ( 0 );
}

On the panel, there is a graph with plots etc. If I quit the program via the quit callback (i.e. a Quit button), everything is fine, no memory leak.

 

If I try a modified version as shown below, plots are not freed after the program has finished, resulting in a memory leak as shown by the resource monitor:

 

int main ( int argc, char *argv [] )
{
...

    RunUserInterface ();
    return ( 0 );
}

 

int CVICALLBACK Quit ( int panel, int control, int event, void *callbackData, int eventData1, int eventData2 )

{
    if ( event == EVENT_COMMIT )
    {

        FreeDynamicMemory...

        FileCloseFiles ...

        DiscardMenuBar ( popup_menubar_handle );
        DiscardMenuBar ( menubar_handle );
        DiscardPanel ( panel_handle );
        QuitUserInterface ( 0 );

    }
    return ( 0 );
}

 

I have also tried reversing the order in the quit callback, with the same result:

 

int CVICALLBACK Quit ( int panel, int control, int event, void *callbackData, int eventData1, int eventData2 )

{
    if ( event == EVENT_COMMIT )
    {

        FreeDynamicMemory...

        FileCloseFiles ...

        QuitUserInterface ( 0 );

        DiscardMenuBar ( popup_menubar_handle );
        DiscardMenuBar ( menubar_handle );
        DiscardPanel ( panel_handle );
    }
    return ( 0 );
}

 

So only the first variant works properly and I could be happy.

 

However, I do not understand why version 2/3 do not work.

Second, the first variant does not work if I also have installed a main callback, see the other thread here That's why I tried variants 2 and 3 but failed...

 

Thanks for the coffee Smiley Wink

0 Kudos
Message 1 of 4
(3,682 Views)

Off the top of my head, I can't think of any reason why the 2/3 alternatives wouldn't work. This might be a bug in the resource tracking detection.

 

I tried to reproduce the problem with a simple program, but I wasn't able to. I'm attaching my files. Can you try them out and see if you can reproduce the problem with them? If not, can you try attaching some project that reproduces it, so that I can look into it?

 

Thanks,

Luis

0 Kudos
Message 2 of 4
(3,654 Views)

Dear Luis,

 

This is correct, your example code behaves properly. The same is true for my code - as long there are no plots on the graph. If I find the time I'll try to provide a sample reproducing the problem.

 

Have a nice day,

Wolfgang

 

 

0 Kudos
Message 3 of 4
(3,634 Views)

Wolfgang,

 

Looks like there was some glitch when I attached my files. I must have attached an earlier file than the one I was using. Sorry about that.

 

The one I was using did have a plot, and I still couldn't reproduce it. This is what I had:

0 Kudos
Message 4 of 4
(3,613 Views)