2

I am using Java, and for logging sl4j/log4j is used. Just out of my curiosity, I want to know that whether writing too much logs can cause Java OutOfMemory error?

What is too much here? Hmm say 100 mb of log in 10 mins while doing excessive db operations (I know that this information is not sufficient for a pin point answer, but even I am not looking for a pin point answer, just want to know in general that can this situation ever come).

Also, my logging process is not asynchronous.

Arry
  • 1,630
  • 9
  • 27
  • 46
  • I think you may be confusing two different subjects. An OOME occurs when there is no more RAM available to create/allocate objects. A logging library such as log4j writes to a physical file as long as there is disk space available. While logging will not cause an OOME it can slow down the application or cause scrolling blindness (see http://logging.apache.org/log4j/1.2/manual.html). – Luis Apr 01 '13 at 04:46

2 Answers2

3

You are getting an error that the heap is exhausted, right? not a PermGen error?

Clearly the logging lib is not leaking, but there's no question that if you wrote some code that created tons of strings in a really short amount of time you could exhaust memory. You would think that would cause a permgen error, as it's hard to imagine your logging objects would be enough to sack the heap.

Excessive db operations are a typical OOME culprit: returning large result sets particularly. I wouldn't call that a memory leak. Leaks usually cause failures after a long time running. If you have a table with a million records and 20 columns and try and return that in a query, that will run until the heap is gone and crash, first time, no leak or reference issues.

How to avoid OOM (Out of memory) error when retrieving all records from huge table?

Community
  • 1
  • 1
Rob
  • 11,446
  • 7
  • 39
  • 57
2

I want to know that whether writing too much logs can cause Java OutOfMemory error?

I very much doubt it.

If you have a problem with OOME's, the most likely cause is a memory leak. You should investigate this methodically, rather than (basically) guess at possible causes.

(If the memory leak was in one of the logging libraries, that would be a bug in the library. This is not impossible, but the chances are that such a bug would have been found and fixed a long time ago.)

Reference: General strategy to resolve Java memory leak?

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216