Memory leak with SyntaxEditorRenderer...

SyntaxEditor for Windows Forms Forum

Posted 18 years ago by Robert Conde - Senior Systems Engineer, a.i. solutions
Avatar
There appears to be memory leak with SyntaxEditorRenderer due to the attachment of the UserPreferencesChanged event. While you attach in the constructor, and detach in the dispose method, the detachment in the dispose method is wrapped in a "if(disposing)" block. Therefore, if dispose is not explicitly called on the renderer, which I'm guessing fails to happen somewhere internally, the finalizer will instead call dispose(false) and the event never gets detached. Good times!!!

[Modified at 04/06/2007 03:13 PM]

Robert Conde

Comments (6)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks for the note, we've removed the "if" check for the next maintenance release.


Actipro Software Support

Posted 18 years ago by Robert Conde - Senior Systems Engineer, a.i. solutions
Avatar
When might that be - we're doing a release in a couple of weeks and we'd like to have that in there.

Robert Conde

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We have a decent number of changes almost ready to go so I imagine that the update will be within a week or so.


Actipro Software Support

Posted 18 years ago by Robert Conde - Senior Systems Engineer, a.i. solutions
Avatar
Ok - so that fix is in...but the issue lives on. It appears each instance of Syntax Editor creates a new VisualStudio2005SyntaxEditorRenderer. I was wrong to suggest merely removing the "if(disposing)" block around the event detach. That doesn't help because the object can never be finalized BECAUSE the static event is attached. So the leak remains. I think Syntax Editor should be disposing it's renderer when it's disposed. I can manually dispose each SyntaxEditor.Renderer when i dispose the SyntaxEditor...but I have a feeling thats not safe. Any suggestions? Bugfix?

I sent an email with a simple project reproducing this problem.



[Modified at 05/22/2007 02:12 PM]

Robert Conde

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Robert,

Thanks for the sample. It seems that the global renderer is being kept "live", even when no other SyntaxEditors are using it any more, because of the tie to the system color change event. The SyntaxEditor instances themselves are disposing fine. So this leak scenario is only happening when the number of active SyntaxEditors reaches zero and then you add a new SyntaxEditor in which case, it creates a new renderer. Since the original one never got removed from memory properly, now you have two. And so on.

Now for an immediate workaround... One way to stop it from happening is to trick the renderer manager into thinking that there is an extra reference to the renderer out there. You can do this by putting this somewhere at the start of your app and retaining a reference to the renderer throughout the lifetime of your app:
 UIRendererManager.IncrementUsageCount(typeof(ISyntaxEditorRenderer), new SyntaxEditorRendererFactory());
renderer = (ISyntaxEditorRenderer)UIRendererManager.GetRendererData(typeof(ISyntaxEditorRenderer)).Renderer;
Please do that until we can sort out a better solution. The solution will probably require updates to the WinUICore library. Thanks!


Actipro Software Support

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I added some code in WinUICore so that when a global renderer is no longer needed, it will call the renderer's Dispose method if the renderer is IDisposable. Since the renderers that tie to the SystemEvents.UserPreferenceChanged event release the event handler when disposed, this fixes the problem going forward.

This code change will appear whenever WinUICore build 91 is released.


Actipro Software Support

The latest build of this product (v24.1.1) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.