1

I am not able to debug the issue ,what are the possibilities it can happen. Can anyone tell me ?

5
  • Lots of possibilities could cause this. Most likely an extremely large ArrayList of Vector. It's hard to know without seeing your code. Does it have a large number of classes or just one or two? Commented Feb 26, 2015 at 10:21
  • Also you can use the '-Xmx' flag with java to increase the heap size. But you really should try to understand what causes it first incase it is a problematic object that is leaking and not being collected by the GC Commented Feb 26, 2015 at 10:22
  • Could you please provide the code? Most common reasons are trying to create a data structure (collection or array) which is bigger than memory available to JVM, infinite loop that keeps inserting elements into collection and infinite recursion. Commented Feb 26, 2015 at 10:24
  • Most probably a memory leak. You should use a profiler and/or a memory leak detector tool such as Valgrind for example. Commented Feb 26, 2015 at 10:28
  • Why are you unable to debug the issue? Can you set -XX:+HeapDumpOnOutOfMemoryError? Commented Feb 26, 2015 at 10:48

3 Answers 3

1

There are some tools available for memory profiling.

1) Eclipse Memory Analyzer (MAT)

2) Java VisualVM

See the reports generated through tools and fix the issue mention in memory profiling reports.

You can use any one of them to generate report

Sign up to request clarification or add additional context in comments.

1 Comment

Just to add to this answer - I recently had a similar problem and managed to track down the issue, using VisualVM I was able to take a heap dump and identify the largest objects in the heap, and work back from there.
0

The simple way - you can use jvisualvm from JDK. In left side select your application, and then perform heap dump on Monitoring tab, then you can found memory leak. Also you can run memory profiler in jvisualvm.

Comments

0

Use command line 'breakpoints'. A few lines in, add something like

System.out.println("Made it thus far!");

or in code with lots of loops, you can use this to make sure that you don't iterate too many times:

System.out.println("Made it thus far! i = " + i1); where i1 is an additional loop counter.

and move it down and down until you get your error instead of that print. This will help determine the line at which the error is occurring.

Please remember to post your code if you can as it makes the job a whole lot easier and you can have your problem solved in under a minute.

6 Comments

Although it will work, most likely you will see millions of these print outs before OutOfMemoryError is thrown. You may as well analyze the stack trace of the error which should show recent method calls.
@JaroslawPawlak Why would you see millions? In simple programs, which, without the intent to insult, sounds like the relative capability of this developer, there likely wouldn't be millions of prints. Although, every program is unique*. Can you name some simple code that would induce high memory usage, be simple, and produce millions of these prints?
@ TheJavaNot-So-Pro Accidental infinite loop that keeps adding elements to collection. Recursive Fibonacci for large input.
If the programmer added a loop counter, and saw it increase beyond the expected iteration count, that would solve the problem.
It really depends on the problem. With more complex algorithms you may not know the expected iteration count. Same with recursion. Anyway, it would be great if Hemant Pandey could post his code.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.