I have a appearance collection for commonly shared appearnace. This collection objects are re-used across different controls to provide consistent look and feel.
However, on profiling the code I observed the reference to the grid is held by the appearance object. That means the grid is not GC since appearance collection is maintained for the life of the application.
Is there are a way to remove the connection between grid and appearance when the grid is ready to disposed ?
Hi,
Okay, I guess what confused me was your very first sentence.
BB said:I have a appearance collection for commonly shared appearnace.
So now you are saying that you are not holding these appearances in a collection?
Anyway, if you have disposed the grid the Appearances should not still be holding a reference to the grid.
If that's happening it's a bug. The grid hooks into change notifications from the Appearance so that when the appearance properties change, the grid knows to update it's display. But those hooks should be removed when the grid is disposed.
You can try setting the DataSource to null, but if disposing the grid did not help, I doubt it will make a difference.
I tried this out in a simple test app, but I cannot reproduce the leak you are describing. I am attaching my sample project here so you can check it out.
I ran this sample through the Ants Memory Profiler 7.
I ran the sample and clicked on the "Show one form" button. I do this first so that any static objects get loaded into memory and the grid assembly is loaded.
Then I take a snapshot.
Then I clicked the "Show ten forms button" and take another snapshot.
At this point Ants reports that there has been no increase in the number of instances of any classes. So there are no extra grid controls hanging around in memory.
I am not using the AppearanceCollection. I have IAppearanceFactory and when I bind the data on InitializeLayout I do the following
column.CellAppearance = appearanceFactory.ReadOnlyAppearance.
On profiler, I am observing a object graph from Appearance === AppearanceHolder === UltraGridDisplayLayout === UltraGrid
Will it help, if on Dispose I set the grid.DataSource = null ?
If you are using Appearances across control, it's probably best not to add those appearances to the Appearances collection of any one control. So I would recommend not storing the Appearances in the grid's Appearances collection. You can just store them in some local member variables.