3 Replies Latest reply on Feb 1, 2007 12:54 PM by 794069

    regex heap out of memory error

    807607
      I am working on an application that is using regular expressions extensively. All the regular expression objects i.e. Pattern, Matcher are defined inside methods and therefore they are local object references so they should be removed by Garbage collector. But what happens is that as the application executes the memory occupied by these objects increases contnously until heap out of memory error occurs. I have also tried to solve this problem by assigning null value to the regex objects but result is same

      Has some one faced this problem and is there any solution to this problem or if this problem is inherent to regex api.
        • 1. Re: regex heap out of memory error
          796254
          You're assuming that it's regex that's causing the OOM error. Profile your code and see if this is true.

          %
          • 2. Re: regex heap out of memory error
            807607
            Well if the garbage collector doesn't get rid of them, something is still referencing them. However, why do you think it is the regex's causes you to run out of memory? I would do some profiling to determine the true cause.

            EDIT: wow, that was slow.
            • 3. Re: regex heap out of memory error
              794069
              memory error occurs. I have also tried to solve this
              problem by assigning null value to the regex objects
              Read: Idioms that are wrong

              "Explicit nulling should be saved for cases where your program is subverting normal scoping rules"

              For most applications, explicit nulling, object pooling, and explicit garbage collection will harm the throughput of your application, not improve it -- not to mention the intrusiveness of these techniques on your program design. In certain situations, it may be acceptable to trade throughput for predictability -- such as real-time or embedded applications. But for many Java applications, including most server-side applications, you probably would rather have the throughput.