LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory not freed after DeleteGraphPlot

Hello,

 

I'm using the graph ctrl for plotting a continuous data stream. Since the data has always to be displayed completely, I'm downsampling the data to a number which is smaller than the displayed amount of points and then go on plotting data points, but with the new downsampling ratio, until the side of the graph is reached again and I have to downsample again.

Now the graph ctrl is always generating new handles for each point I'm adding. Since the graph runs for days, this generates a memory problem over time.

 

Now here comes my problem:

The memory is NOT freed when I use the DeleteGraphPlot function. Even worse, I can delete the whole ctrl with DiscardCtrl, the memory is still used. I don't see any option to prevent my graph from filling my memory more and more until the whole system gets terribly slow because of the memory being dumped on the HDD.

One might say that

SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_COPY_ORIGINAL_DATA, 0);

should help, but it only slows the process down.

I know that

SetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_DATA_MODE, VAL_DISCARD);   

solves this issue, but since my window can be resized and I constantly add plots, this is not an option.

How can I free the memory occupied by the Plots?

If someones interested: I'm running latest CVI version (2015 SP1) on Windows7.

Best regards,

    Thomas

 

0 Kudos
Message 1 of 6
(3,234 Views)

Hi,

 

Have you tried to set the handle to –1 to delete all plots in the graph control.

DeleteGraphPlot (hPanel, GRAPH, -1, VAL_IMMEDIATE_DRAW);

0 Kudos
Message 2 of 6
(3,216 Views)

Hi,

 

this is exactly what I'm doing, but the memory doesen't get freed.

 

Best

  Thomas

0 Kudos
Message 3 of 6
(3,211 Views)

I'm not sure if this can be a good solution, but I would try rewriting actual plot data array: hopefully it does not imply a new memory allocation.

 

// Get plot data
GetPlotAttribute (panelHandle, PANEL_GRAPH, plotHandle, ATTR_PLOT_YDATA, data);

// Rewrite the array

// Set plot data
SetPlotAttribute (panelHandle, PANEL_GRAPH, plotHandle, ATTR_PLOT_YDATA, data);


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 4 of 6
(3,203 Views)

It's definitely unexpected for your program to start running out of memory if all you are doing is deleting old plots and plotting new ones.

 

Do try to confirm that your total number of plots isn't increasing over time (you can use the ATTR_NUM_PLOTS attribute for this). If that number is staying relatively constant, and if the number of points in your new plots isn't dramatically higher than that of the old plots, the total amount of memory shouldn't really be increasing.

 

To be clear, if you are using some external tool, such as Task Manager or Process Explorer to monitor the amount of memory used by your program, you won't necessarily see this memory go down as soon as you call DeleteGraphPlot or even DiscardCtrl (although you might, if you call DiscardPanel). However, this doesn't mean that the memory that you freed by deleting those plots is still in use. As an optimization, the CVI runtime does its own memory management, and it usually holds on to memory that your program frees for a while, so that it doesn't have to re-allocate it from the system the next time that you program needs to increase its usage again. So the practical effect of you freeing your plots is that the next time you add a new plot your memory won't increase. The end result should still be that the total system memory used by your program will not increase over time.

 

If you can create a simplified version of your program that continuously adds new plots and deletes old plots, and the total amount of memory keeps increasing over time, we would love to use it to investigate this further, since it definitely sounds like a bug somewhere.

 

Luis

0 Kudos
Message 5 of 6
(3,142 Views)

This reminds me of something... Wasn't there a memory handling bug in the plot routine of some previous version of CVI ? What version are you using ? I think I opened a ticket years ago about that.

0 Kudos
Message 6 of 6
(3,139 Views)