Unplanned
Last Updated: 17 Jan 2020 15:27 by ADMIN
LindenauAtSOG
Created on: 08 Jan 2020 15:10
Category: GridView
Type: Bug Report
4
GridView: RadGridView is held in memory after the control is unloaded when the IsPropertyChangedAggregationEnabled property is True

We noticed that RadGridView does not get garbagecollected sometimes.
So i fired up  a memory analyzer to see what is going on.

This is the graph that shows that the RadGridView is causing a leak. The only references that keep the GridView from getting collected are those two WeakEventListeners

To further investigate i decompiled GridViewDataControl and could identify the culprit.

private void SubscribeToDispatcherShutdown()
    {
      if (this.dispatcherShutdownListener != null)
        this.dispatcherShutdownListener.Detach();
      this.dispatcherShutdownListener = new WeakEventListener<GridViewDataControl, object, EventArgs>(this);
      this.dispatcherShutdownListener.OnEventAction = (Action<GridViewDataControl, object, EventArgs>) ((grid, source, eventArgs) => grid.OnDispatcherShutdownFinished(source, eventArgs));
      this.dispatcherShutdownListener.OnDetachAction = (Action<WeakEventListener<GridViewDataControl, object, EventArgs>>) (weakEventListener => this.Dispatcher.ShutdownFinished -= new EventHandler(this.dispatcherShutdownListener.OnEvent));
      this.Dispatcher.ShutdownFinished += new EventHandler(this.dispatcherShutdownListener.OnEvent);
    }

In the second line from the botton

... weakEventListener => this.Dispatcher.ShutdownFinished -
... you are using 'this.Dispatcher...' which causes the leak since the Action will implicitly capture the 'this' reference.
Which kind of defeats the prupose of having a WeakReference inside your WeakEventListener.

Sadly i cannot figure out how it happens, but i think its only when Detach (FrameworkElement.Unloaded ultimately) is not called.
While this is the actual issue, i thought I'd share this with you so you.

7 comments
ADMIN
Dilyan Traykov
Posted on: 17 Jan 2020 15:27

Hello,

Thank you for the additional details.

I will approve this bug report so that other users with the same issue can find it but unless we can replicate the issue at our end in a small sample project, we cannot apply a valid fix for the time being.

Please let us know if you can manage to isolate the memory leak in a small sample project and we would then happily test the proposed fix.

Regards,
Dilyan Traykov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
LindenauAtSOG
Posted on: 14 Jan 2020 13:20
LindenauAtSOG
Posted on: 14 Jan 2020 12:19

The thing is, I do not know when exactly it happens, but it does sometimes.

But it seems that FrameworkElement.Unloaded or Window.Unloaded to be more precise seems to have a known issue from my quick googlesearch on this matter.

Maybe it is connected to the fact that we are using your TabbedWindow control.
I am afraid i cannot provide you any further details in this case.

We dont have any trouble with it though, since the memoryconsumption is negligible.

LindenauAtSOG
Posted on: 14 Jan 2020 12:02
Thankyou for the provided details though.
LindenauAtSOG
Posted on: 14 Jan 2020 12:01
I wasnt directly asking for help on that memory leak. I only wanted to bring this to your attention that there is a bug in your code.
ADMIN
Dilyan Traykov
Posted on: 14 Jan 2020 11:42

Hello,

Thank you very much for the provided image, snippets, and valuable feedback.

Although the fix you suggested does seem reasonable, we need to be able to replicate the issue you described at our end in order to perform testing whether the suggested modification actually solves it. Please let us know if you would be able to isolate the memory leak in a small sample project so that we can further investigate at our end.

In the meantime, as the SubscribeToDispatcherShutdown method is only invoked if the IsPropertyChangedAggregationEnabled property is set to True (which is the case by default) I can recommend setting if to False for the time being. Unless you make a large number of updates in your data items for a short period of time (1000 per second, for example) this should not impact the performance of your application.

Please let me know if this would work for you for the time being.

Regards,
Dilyan Traykov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
LindenauAtSOG
Posted on: 10 Jan 2020 06:38
I forgot to mention that other method that subscribes to that other event is faulty aswell.