Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. out-of-memory exception thrown when using Find

out-of-memory exception thrown when using Find

Scheduled Pinned Locked Moved C#
helpalgorithmsperformancetutorialquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    clatten
    wrote on last edited by
    #1

    I use the code below for a simple search function in a richtextbox. When I load larger files, and try to search it will always throw an out-of-memory exception. From the debugging it seems to be richTextBox.Find that is the culprit. For an example, searching File1 that is 1800kB is no problem but File2 at 17000kB will always throw the exception. Opening File2 in, for example Notepad, and search is no problem. Anyone knows why, is there a limitation with richTextBoxes and why can I then load the file with the Loadfile function? Is there any workaround for it? I also ran into another problem, with one specific file I don't get the exception when I search but instead "Failed to load resources from resource file. Please check your setup". I use the default settings and I did run the "fix application". Still it will crash with this message. Any fix for this? try { RichTextBox.SelectionColor = Color.Black; int searchEnd = RichTextBox.TextLength; searchStart = RichTextBox.Find(searchTextBox.Text, searchStart, searchEnd, RichTextBoxFinds.MatchCase); RichTextBox.SelectionColor = Color.Blue; //RichTextBox.SelectionFont = Font.Bold; RichTextBox.GetPositionFromCharIndex(searchStart); RichTextBox.Focus(); RichTextBox.ScrollToCaret(); if ( searchStart < searchEnd ) { searchStart++; } else { searchStart = 0; } } catch (Exception f) { MessageBox.Show("Failed to search " + searchFile + "\n" + f.ToString()); }

    C 1 Reply Last reply
    0
    • C clatten

      I use the code below for a simple search function in a richtextbox. When I load larger files, and try to search it will always throw an out-of-memory exception. From the debugging it seems to be richTextBox.Find that is the culprit. For an example, searching File1 that is 1800kB is no problem but File2 at 17000kB will always throw the exception. Opening File2 in, for example Notepad, and search is no problem. Anyone knows why, is there a limitation with richTextBoxes and why can I then load the file with the Loadfile function? Is there any workaround for it? I also ran into another problem, with one specific file I don't get the exception when I search but instead "Failed to load resources from resource file. Please check your setup". I use the default settings and I did run the "fix application". Still it will crash with this message. Any fix for this? try { RichTextBox.SelectionColor = Color.Black; int searchEnd = RichTextBox.TextLength; searchStart = RichTextBox.Find(searchTextBox.Text, searchStart, searchEnd, RichTextBoxFinds.MatchCase); RichTextBox.SelectionColor = Color.Blue; //RichTextBox.SelectionFont = Font.Bold; RichTextBox.GetPositionFromCharIndex(searchStart); RichTextBox.Focus(); RichTextBox.ScrollToCaret(); if ( searchStart < searchEnd ) { searchStart++; } else { searchStart = 0; } } catch (Exception f) { MessageBox.Show("Failed to search " + searchFile + "\n" + f.ToString()); }

      C Offline
      C Offline
      clatten
      wrote on last edited by
      #2

      Embarrassingly enough I believe the out-of-memory was due to that I dodn't took care of when there was no hit on the search. The failed to load resources probelm remains though.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups