Possible LexicalPatternGroups memory leak

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Adam Dickinson
Avatar
In SyntaxEditor 3.1.203 .NET 1.1 Visual Studio 2003:

I have a multiply-tabbed application that creates a SyntaxEditor for each document loaded. I have routines that parse the language and create 2 LexicalPatternGroups and fills each of them with LexicalPatterns. The language gets updated at run-time as new syntax keywords are created by the user.

I get a large memory leak when I update with the following method:
1) Find my 2 LexicalPatternGroups and if found, remove them from the "DefaultState" LexicalState's pattern groups. (I even tried calling a Clear() and a Dispose() but still a large leak)
2) Create 2 new LexicalPatternGroups and add them to the LexicalState's pattern groups.
3) Create new LexicalPatterns and add them to the appropriate group.

I get a smaller memory leak when I update this way:
1) Find my 2 LexicalPatternGroups, and if found, clear them. Otherwise, create them.
2) Create new LexicalPatterns and add them to the appropriate group.

I get no memory leak when I update this way:
1) Create a cache of LexicalPatterns.
1) Find my 2 LexicalPatternGroups, and if found, clear them. Otherwise, create them.
2) Add the appropriate LexicalPattern from the cache to the appropriate group.

This last method is great because it saves a lot of memory, avoids the apparent memory leaks, and saves some processing time. However, I have problems if I ever need to reload the file (if it is changed outside of my editor).

Object reference not set to an instance of an object:
at ActiproSoftware.SyntaxEditor.LexicalState._1(StringBuilder , Int32& , Int32 , LexicalPattern& )
at _23._1(SyntaxLanguage , StringBuilder , Int32& , Int32 , _22 , Token , Int32 )
at ActiproSoftware.SyntaxEditor.Document._1(DocumentModification )
at ActiproSoftware.SyntaxEditor.Document.set_Text(String value)
at ActiproSoftware.SyntaxEditor.Document.LoadFile(String path)
I prompt the user to reload the modified file, and the catch is that LoadFile won't fail unless I have 2 prompts open and you choose to reload on the 2nd prompt.

So… memory leak: real or no?
Proper way to dynamically alter the language at run-time?
Anything special I need to be aware of when reloading a file, in general?

[Modified at 05/25/2006 04:00 PM]

Comments (10)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Adam,

Before we look into this further, may I ask, are you setting IsUpdating = false on the language before you make ANY changes and IsUpdating = true afterwards? That is a requirement and may be the cause of your problems if you aren't doing it since it won't remove some references if you don't do those things.


Actipro Software Support

Posted 13 years ago by Adam Dickinson
Avatar
Yes, I am before updating the language, but I'm not before and after I do the (re)load.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
If you don't set IsUpdating to false after you do any changes, then that is probably the reason why it is retaining references. You need to add that line in.


Actipro Software Support

Posted 13 years ago by Adam Dickinson
Avatar
I'm sorry, my wording wasn't precise. I set IsUpdating properly before AND AFTER updating the language.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ok in that case, could you make a tiny project that shows the issue and email it to us? We can use that with our memory tool to try and narrow down what is happening.


Actipro Software Support

Posted 13 years ago by Adam Dickinson
Avatar
Just sent the zip with a sample solution to your email. You should receive it shortly.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Adam,

Thanks for the sample. I debugged it using our memory tool and did find a minor bug. Basically if you reparsed a document (which happens when IsUpdating = false), the editor.Document.Tokens.DeletedTokens collection was not cleared before the existing tokens were added to it. Therefore, the old Tokens with references to the old pattern groups were retained in memory.

However, as soon as you made any sort of document modification (programmatically or by typing), that collection was cleared. So really you only saw the memory increase as long as you reparsed the document without making any text changes. After a text change was made, the problem went away.

Anyhow, this issue is fixed for the next maintenance release.


Actipro Software Support

Posted 13 years ago by Adam Dickinson
Avatar
Excellent. Thank you so much!
Posted 13 years ago by Adam Dickinson
Avatar
btw, when is the next maintenance release? i can't seem to find anything about a regular release schedule or something similar. Thanks again.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Not sure when the next release will be yet. We release when we have queued up several new features or bug fixes, or if something major needs immediate implementation.

But in your situation, it really won't cause any issues as long as the end user is doing any sort of text change since typing or anything resets the memory that was retained from the language update.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 6 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.