Issue loading large files

SyntaxEditor for WPF Forum

Posted 6 years ago by \アッカリーン/
Version: 13.1.0581
Avatar

I'm having an issue loading some large log files (around 100 MB of straight text). In my main application, I'd notice that sometimes when I used the LoadFile function, I'd get back a blank SyntaxEditor (with no text loaded), and every once in a while I'd get a crash, so I made a separate application with just the SytaxEditor control on it, and made a button that runs the following:

SyntaxEditor.Document.LoadFile(@"u_ex111121.log");

 The first time you hit the button, the file loads properly. The second time you hit the button, the application crashes with the following:

System.OutOfMemoryException was unhandled
  HResult=-2147024882
  Message=Exception of type 'System.OutOfMemoryException' was thrown.
  Source=mscorlib
  StackTrace:
       at System.String.CtorCharArray(Char[] value)
       at #PZc.#RZc.ToString(Int32 #Oqc, Int32 #Nqc)
       at ActiproSoftware.Text.Implementation.TextDocumentBase.#O7c(#g7b #g7b)
       at #Q2b.#g7b.Apply()
       at ActiproSoftware.Text.Implementation.TextDocumentBase.SetText(String text)
       at ActiproSoftware.Text.Implementation.TextDocumentBase.LoadFile(String path)
       at fire_error.MainWindow.Button_Click(Object sender, RoutedEventArgs e)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.Controls.Primitives.ButtonBase.OnClick()
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at fire_error.App.Main()
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

 Using one of the overloaded LoadFile functions produces the same exception:

            using (FileStream fs = File.OpenRead(@"u_ex111121.log"))
            {
                SyntaxEditor.Document.LoadFile(fs, Encoding.UTF8);
            }

 Is there anything I'm doing wrong here? My main application seems to have issues, even when creating a new SyntaxEditor control each time a new file is loaded.

Thanks!

Comments (2)

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

Hello, the WPF SyntaxEditor is set up to try and handle large files as well as it can.  Still you have to consider that a 100MB file probably loads in memory as 200MB+ due to .NET strings being Unicode (double byte).  So then when you load it a second time, now you are temporarily having over 400MB of memory used. 

There aren't any memory leaks in the WPF SyntaxEditor that we are aware of so my guess is that you are just pushing the total memory over what the device is able to handle.

If you have to open files of that size, I'd probably suggest you use the PlainText language (since it has no lexer, meaning no memory will be taken up for token data).  And also you would probably want to consider breaking up the file into more digestible chunks of 10MB or so.


Actipro Software Support

Posted 6 years ago by \アッカリーン/
Avatar

Hi there,

Your post gave me an idea. I changed the compile options to force to x64, rather than leaving it up to .NET, and I assume the app was running in x86 mode for some reason, because this removed any problems I was having. This machine has more than enough ram to handle 2-4 GB being used up. Hopefully this helps anyone else who may run into this. You might have to switch your compile settings to force x64.

The latest build of this product (v2019.1 build 0682) was released 0 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.