-2

Today while working i encountered this problem in one of our application. Scenario is: We have a load button by clicking on it, it will load lacks of records from the data base. But the issue is while reloading the same records by clicking on refresh button it is giving OutOfMemoryError. Can anyone give brief explanation what might be the possible cause because at first attempt it is loading all the records fine but why we are getting exception on refreshing it.

If any good resource available to study this scenario also would help alot. Thanks in advance...

  • 1
    Are you making sure the old results are no longer taking up memory when reloading them? – Mark Aug 22 '16 at 09:51
  • this can help https://plumbr.eu/outofmemoryerror/java-heap-space – dhS Aug 22 '16 at 09:53
  • This project was already developed and from past week i am working on it, i don't have much depth knowledge on it. can you please suggest how i can make sure that old results are no longer taking up memory? Sorry to say but for security and company policy sake i can't post the code here? If general expatiation also helps me a lot. Thanks. – Pavan Singh Aug 22 '16 at 09:58
  • The first time the SQL Statement and ResultSet must have been closed (using JDBC), and any existing list must be cleared at the start of the button press. – Joop Eggen Aug 22 '16 at 10:06
  • Thank you Eggen for helping, the issue is solved now. – Pavan Singh Aug 23 '16 at 11:26
  • Without a stack trace your question is in answetwble, and with one it answers itself. – user207421 Aug 23 '16 at 11:43

2 Answers2

0

The only reason is that you are constantly creating new objects without freeing enough, or you are creating too many threads.

You can use Java VisualVM's profiler to do some memory profiling. This allows you to get an overview, which objects are in memory, and which other object/thread has references to them.

The Java VisualVM should be part of Sun's JDK.

See also:

Community
  • 1
  • 1
Martin Nyolt
  • 3,706
  • 2
  • 22
  • 33
-2

I came to know that our application has lots of thread processing. I tried to reduce the stack size in the server by using the below command and it worked.

-Xss512k (setting the java thread stack size to this)

Here is the resource like i have used to resolve this issue.

N00b Pr0grammer
  • 3,930
  • 4
  • 28
  • 40
  • This does not answer the question of the *causes*. Could you confirm that you created too many threads, so that the accumulated stack size was actually exceeding some limit? – Martin Nyolt Aug 23 '16 at 11:37