View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0000435 | NoesisGUI | Unity | public | 2014-08-02 03:34 | 2018-11-21 13:47 |
| Reporter | ai_enabled | Assigned To | sfernandez | ||
| Priority | high | Severity | major | ||
| Status | assigned | Resolution | open | ||
| Summary | 0000435: Circular references in GC with event handlers | ||||
| Description | Hello! | ||||
| Attached Files | |||||
| Platform | Any | ||||
|
Hello! |
|
|
Hi, I've been doing some tests and after playing around 15-20 minutes the timings of our Update vary almost nothing. I've been killing some pirates, docking in the station, talking to the civilians, navigating through skill tree... I will leave the game running during a few hours and see if it degrades then. Is there anything special I should do to force the degradation more? |
|
|
It's not degrading after something special, we're notice constant degradation over play time. Usually after 2 hours the game became unplayable because of a serious FPS drop as reported by many customers. Not sure if it will drop if you just leave your PC for a few hours. |
|
|
I have a clue. Time is growing on the animation manager. |
|
|
Hello! Do you have any progress? I can provide you game sources if you need it. This issue is critical for us... |
|
|
Hi, I detected that animated objects and properties are growing any time I enter the SKILLS tab. 66 new objects are added to the Animation manager and never deleted when leaving the tab. Are you using "Forever" animations? That will explain why animations are never removed from the manager. |
|
|
Thanks for investigation! I've added some test code, and found that we have serious amount of controls, which are not referenced by anyone (which was simply removed from collection and expected to be garbage collected) and not automatically garbage collected (I tried forcing it). Issue with skill icons is very strange. They're placed in specific panel control, which is placed via TabItem.RefreshContent() method to TabItem. So when I invoke TabItem.RefreshContent(null), this icons and they parent became abandon controls and should be collected by garbage collector, but this never happens. Is this behaviour of abandoned controls normal and I should always remember to manually dispose all unused instances? I'm sure they can be disposed automatically, but some references still hold by someone. Is not easy to determine by who exactly - there is no such feature in Mono/.NET. |
|
|
The SkillIconControl.xaml seems correct, nothing strange that could lead to this situation. We recently discovered a big problem that could explain why objects are not released, but I don't know if it can apply to your scenario. When you have a control, and in its code-behind you attach a delegate to an event of the control or any of the children elements, a strong reference to the control is stored by the C# delegate, so control is never disposed unless you remove the delegate. For example, imagine a UserControl with a button inside: public class MyControl : Noesis.UserControl
}This control will never be disposed, because Click event maintains a strong reference to the control. We are very worried about this situation and solve it is one of our priorities. Let me know if this is the problem you are experiencing. |
|
|
I thought about it also and found that actually we're using event handlers in the skill icons control... |
|
|
Our base classes for controls using two events:
But it's preventing garbage collection of any inherited control... but we absolutely can't live without it! |
|
|
I just come up with an idea that maybe will be the internal solution we are going to adopt. The problem here is that event delegates (which maintain a strong reference to the object) are (and need to be) stored in a static table. So GC is unable to detect circular references and dispose the object when nobody else is referencing it. So we need to break this strong reference somewhat. To do it we are going to introduce an indirection. We create an intermediate class that will hold a weak reference to the control object, and that class will be the one attached to the event: [Noesis.Extended]
}Does it make sense? |
|
|
Thanks! This solution works, but it's a little bit "boilerplate" solution and the EventManager instance will remains into memory if you don't hang down events explicitly. It's requires writing some extra code just to wrap the events correctly, but it's reasonable if there are no better solution. Have you read this article about weak references? http://www.codeproject.com/Articles/29922/Weak-Events-in-C Maybe you can invent something better. But the way, we just released new version of the game with fixed controls instantiating (and very high reusing of them). It still contains small "controls leak" due to OnLoaded/OnUnloaded hard references, but performance is much better now. Thanks for you help! |
|
Yes, this must be considered a temporal solution until we fix it internally.
But now is possible because your control is disposed, so in the UserControlBase (or whatever name you are using) destructor, you can unregister from Loaded/Unloaded events (you only need to keep a reference to the EventManager created in the OnPostInit).
This is totally the idea, we will expose Weak Events instead, so you don't have to worry about anything. |
|
|
Hi guys, I just want to check if you will improve this with v1.3 or we will need to keep the workaround? Thanks! |
|
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2014-08-02 03:34 | ai_enabled | New Issue | |
| 2014-08-05 14:01 | sfernandez | Assigned To | => sfernandez |
| 2014-08-05 14:01 | sfernandez | Status | new => assigned |
| 2014-08-08 10:21 | ai_enabled | Note Added: 0001487 | |
| 2014-08-08 15:16 | sfernandez | Note Added: 0001489 | |
| 2014-08-08 15:16 | sfernandez | Status | assigned => feedback |
| 2014-08-08 16:10 | ai_enabled | Note Added: 0001491 | |
| 2014-08-08 16:10 | ai_enabled | Status | feedback => assigned |
| 2014-08-08 16:56 | sfernandez | Note Added: 0001492 | |
| 2014-08-08 16:56 | sfernandez | Status | assigned => feedback |
| 2014-08-12 03:08 | ai_enabled | Note Added: 0001494 | |
| 2014-08-12 03:08 | ai_enabled | Status | feedback => assigned |
| 2014-08-12 19:37 | sfernandez | Note Added: 0001496 | |
| 2014-08-12 19:37 | sfernandez | Status | assigned => feedback |
| 2014-08-13 09:09 | ai_enabled | Note Added: 0001502 | |
| 2014-08-13 09:09 | ai_enabled | Status | feedback => assigned |
| 2014-08-13 09:09 | ai_enabled | File Added: SkillIconControl.xaml | |
| 2014-08-13 09:11 | ai_enabled | Note Edited: 0001502 | |
| 2014-08-13 09:11 | ai_enabled | Note Edited: 0001502 | |
| 2014-08-13 09:14 | ai_enabled | Note Edited: 0001502 | |
| 2014-08-13 09:14 | ai_enabled | Note Edited: 0001502 | |
| 2014-08-13 16:50 | sfernandez | Note Added: 0001505 | |
| 2014-08-13 16:50 | sfernandez | Status | assigned => feedback |
| 2014-08-13 18:32 | ai_enabled | Note Added: 0001506 | |
| 2014-08-13 18:32 | ai_enabled | Status | feedback => assigned |
| 2014-08-15 12:11 | ai_enabled | Note Added: 0001507 | |
| 2014-08-15 12:12 | ai_enabled | Note Edited: 0001507 | |
| 2014-08-15 13:36 | sfernandez | Note Added: 0001508 | |
| 2014-08-15 13:36 | sfernandez | Status | assigned => feedback |
| 2014-08-15 17:22 | ai_enabled | Note Added: 0001509 | |
| 2014-08-15 17:22 | ai_enabled | Status | feedback => assigned |
| 2014-08-15 17:23 | ai_enabled | Note Edited: 0001509 | |
| 2014-08-15 17:23 | ai_enabled | Note Edited: 0001509 | |
| 2014-08-15 18:46 | sfernandez | Note Added: 0001510 | |
| 2014-08-15 18:46 | sfernandez | Status | assigned => feedback |
| 2015-07-23 02:38 | jsantos | Category | Unity Package => Unity3D |
| 2015-10-08 20:03 | jsantos | Summary | Performance degrade greatly over time => Circular references in GC with event handlers |
| 2016-01-04 11:59 | ai_enabled | Note Added: 0003427 | |
| 2016-01-04 11:59 | ai_enabled | Status | feedback => assigned |
| 2016-01-04 11:59 | ai_enabled | Note Edited: 0003427 | |
| 2018-11-01 02:14 | jsantos | View Status | public => private |
| 2018-11-21 13:47 | jsantos | View Status | private => public |
| 2018-11-21 13:47 | jsantos | Platform | => Any |
| 2025-10-10 13:29 | jsantos | Category | Unity3D => Unity |