Memory Leak with Telerik Objects

0 Answers 28 Views
ScheduleView Styling TabbedWindow
Anastasios
Top achievements
Rank 1
Anastasios asked on 12 Mar 2025, 12:58 AM

Hello dear community.

We have a problem, which results in references not being cleaned up properly and the memory leaking over time.

 

The application works like this:

We have a RadTabbedWindow, with RadTabItems. Those RadTabItems have Views with ViewModels (MVVM), injected via PRISM.

Now when we close the tab, the view is not unloaded or garbage collected. When analysed with Resharper DotMemory, you can see that in this example the StyleSelectors or the ResourceDictionarys keep it referenced and thus not allowing it to be collected.

 

To find a Solution to the problem, we have broken down the control to the most simple elements (Simplified ScheduleView.txt). When tested, we noticed that Events and StyleSelectors are keeping the items referenced. So we wrote an UnloadBehavior (which is executed when closing the tab). There is a lot more code in it, handling other stuff, but in the uploaded file (UnloadBehavior.txt) I have only left the stuff regarding this particular case.

 

You can see in MasterViewTop1.png (1 being the top, 2 the middle, 3 the bottom) the reference path.

 

In this particular code, the two StyleSelectors:

GroupHeaderStyleSelector
AppointmentStyleSelector

hinder the cleaning up.

When I give the RadScheduleView a x:Name Property and use them in code behind to set those StyleSelectors to null, it gets unloaded.    Example: ObjectName.GroupHeaderStyleSelector = null;

 

But our application is gonna be big and we need a general solution. We don't want to give each object a name and unload StyleSelectors, Events, etc.. in the code-behind and set them to null. We need a general solution.

 

I can assure that neither the ViewModel, nor the code-behind is at fault. At this particular case, it's just those two StyleSelectors. I know about events, because the RadTimeBar causes the same problem, but with the VisiblePeriodChanged property, which is an event. But we want to solve this step first, which will probably solve all other problems, too. We just need to understand what has gone wrong.

 

Does anybody have an idea what can be done or what is wrong with the code?

I can guarantee that the UnloadBehavior is executed and reaches the DependencyProperties of the RadScheduleView and also sets them to null. But for some reason the objects and the view stay in the memory, even though they don't when I manually do it in the code-behind.

 

To summarise:

- We need a general solution to unload Telerik objects and clear up references for Events, StyleSelectors and everything referencing and locking the UserControl to be garbage collected.

- When done in Code-Behind it works, but when done in the UnloadBehavior nothing happens.

Dimitar
Telerik team
commented on 12 Mar 2025, 08:04 AM

Hello Anastasios,

In general, you do not need to worry about memory in .NET. The garbage collector handles this. However, its execution depends on many things (current available memory, processor load). There is no general solution and no need to manually dispose of the objects. It is possible to create a memory leak but this should be handled for each case. 

I have examined the images and the code but without a runnable project, I cannot properly investigate and say if there is a memory leak and what causes it. Would it be possible to create a sample project that reproduces this and attach it here or open a new ticket? 

I am looking forward to your reply.

 
Anastasios
Top achievements
Rank 1
commented on 12 Mar 2025, 08:36 PM

Thank you very much for your reply!

 

I'm working on simulating the environment. So I will upload it the following days.

Hopefully this will give some insight.

 

Greetings and thanks again!

 


No answers yet. Maybe you can help?

Tags
ScheduleView Styling TabbedWindow
Asked by
Anastasios
Top achievements
Rank 1
Share this question
or