Hi
I'm trying to understand some memory problems with my app and I need a basic understanding of how wingrid manages memory.
I have a button which executes a SQL query and returns a DataSet. The DataSet obviously owns an amount of memory
I then bind the DS to the grid using:
ultraGrid1.SetDataBinding( null, null ); ultraGrid1.SetDataBinding( oDS, null );
Q1: Does wingrid copy all of the data from the DataSet into the grid? Is my original DS unchanged?
Q2: If I press the button a 2nd time to repeat I will get a 2nd DataSet. Is my original DS still in memory? Does it go out of memory when ultraGrid1.SetDataBinding( null, null ); is called?
If I look at the app using Task Manager the memory just keeps going up until I get an out of memory exception
Thanks
Hello,
Thank you for contacting Infragistics Developer Support.
The BindingManager is responsible for the synchronization of data-bound controls on a Windows Form. You shouldn’t remove it as it is vital part of how data binding in WinForms works. Here is a link to the MSDN BindingManager article:
http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingmanagerbase(v=vs.110).aspx
As for your other concern, I created a small test using the code snipped you provided. In my test I repeatedly create a data source and add a table to it with 20 columns and 10000 rows. After doing that a 100 times and forcing the GC to collect the unreferenced objects the used memory basically remains the same. So I don’t believe that resetting the data source the way you do it will cause memory leaks.
I have attached my test sample for your reference.
Please let me know if you have any additional questions.
Thanbks for your quick reply.
The DataSet is new each time.
So, when I call:
DataSet oDS = GetMeSomeData()
ultraGrid1.SetDataBinding( null, null )
ultraGrid1.SetDataBinding( oDS, null )
is my original DataSet still in existence?
I'm not familiar with the BindingManager (even though I have used Wingrid for years). Is this something that I have to get rid of?
gstanbury said:Q1: Does wingrid copy all of the data from the DataSet into the grid? Is my original DS unchanged?
No, and yes. The grid doesn'y create any kind of copy of the data, although the grid does create structures of it's own that will mirror the data source. For example, the grid will create bands and columns to represent the tables and fields in the data source. For the data itself, the grid will often request the data value of a particular field and put that data into a UIElement to display as a string or image, etc.
The Datasource is not change in any way at this point (assuming you haven't changed any of the cells in the grid). But the DotNet framework will create a BindingManager to help communicate between data source and the grid and maintain the current position.
gstanbury said:Q2: If I press the button a 2nd time to repeat I will get a 2nd DataSet. Is my original DS still in memory? Does it go out of memory when ultraGrid1.SetDataBinding( null, null ); is called?
Pressing this button a second time will disconnect the grid from the DataSet and then reconnect it. No new DataSet is created (since you are still referencing the same oDS variable). Your original DataSet is still in memory (assuming nothing in your other code outside of this button disposed it).
If the memory is increasing every time you do this, then it's possible it's a memory leak in the grid, or the BindingManager or in some other part of your code like one of the grid's event handlers.