Out of memory exception when loading

SyntaxEditor for WPF Forum

Posted 7 years ago by Frederic Gregoire
Version: 17.2.0660
Avatar

Hello, I've encountered a few issue upon loading a file into the syntax editor. The main issue is the out of memory exception being thrown when using the LoadFile method of the EditorDocument.

The files that I'm trying to load are around 150MB+. So here are my two questions:

1. Is there a way to avoid this exception?
2. Is there some functionalities that I could disable to enable plain text in the syntax editor? Which one would you suggest?

Thanks in advance!

Frederic Gregoire.

Comments (3)

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Which syntax language are you currently using, one of ours or one of your own?  If the language as features like AST building, it certainly can add up to a good amount of memory, especially for very large documents like that.  The exception you are getting is a system-level one though.  The only way to reduce memory is to use smaller document sizes, or remove some/all language features when editing larger documents.

The SyntaxLanguage.PlainText language could be set to your doucment to effectively use minimal language-related features, allowing SyntaxEditor to be a pure black and white editor.

If your language has certain features you don't mind losing, like the IParser service (if any), you could unregister the parser service from the language.  Depending on the language implementation, that will likely affect downstream features though, such as code outlining, etc.


Actipro Software Support

Posted 7 years ago by Frederic Gregoire
Avatar

Hi, thanks for the swift response,

I'm currently using my own language that uses a dynamic lexer, but should be changing to a programmatic lexer soon to increase the performance even though I doubt this will solve the memory issue.

I've tried your suggestions and assigned the SyntaxLanguage.PlainText language to the editor and unregistered all the services, but I'm still getting the out of memory exception when loading a big file.

I've also tried separating the file into multiple parts to load them one after the other. Each part would simply append the text in the editor, but appending the text can take quite some time (up to a few minutes). Is there any other way I could do this more efficiently?

Thanks,

Frederic Gregoire.

[Modified 7 years ago]

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Frederic,

When you load a document with the PlainText language set, most of the memory is simply the document text.  Note that strings in .NET use two bytes for each character.  So a 150MB document that is saved with an encoding that is optimized for space, could use 300MB in memory for text strings alone.  Beyond that, we shouldn't be using too much additional memory when PlainText is the language.  If you are running into memory issues with that size file and PlainText loaded, you might just have to stick with loading up smaller files or individual sections of the large file.

SyntaxEditor will only run the lexer (for syntax highlighting purposes) from the document start to the text being displayed in the editor.  It won't lex the entire document on load.  When lexing occurs, we store the contextual information for each line end so lexing can pick up incrementally later on document edits.  But we don't store the entire token stream in memory.


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.