Bug 16998 - JDBCAppender leaks memory
Summary: JDBCAppender leaks memory
Status: RESOLVED DUPLICATE of bug 14827
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: 1.2
Hardware: Other other
: P3 normal
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-12 14:58 UTC by Roland Nygren
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roland Nygren 2003-02-12 14:58:31 UTC
The class org.apache.log4j.jdbc.JDBCAppender in Log4j 1.2.7 (and probably 
earlier too) leaks memory. In the method flushBuffer() values are added to the 
ArrayList removes (removes.add(logEvent)), but this ArrayList is never cleared 
or values removed. After some time this will end up with an OutOfMemoryError.
In my example of flushBuffer() below there will be no memory leak.

Besides this we have some ideas about improving performance for user threads
by adding a thread that handles the database writing.

  public void append(LoggingEvent event) {
    buffer.add(event);
    if (buffer.size() >= bufferSize)
      logThread.wakeup();
  }
  public synchronized void flushBuffer() {
    LoggingEvent logEvent = null;
    while (buffer.size() >0) {
      try {
        logEvent = (LoggingEvent)buffer.remove(0);
      } catch(Exception ignore){
        break;
      }
      try {
        String sql = getLogStatement(logEvent);
        execute(sql);
      } catch (SQLException sqle) {
        // Unable to store LogEvent i database, put it back in buffer.
        if (logEvent != null)
          buffer.add(logEvent); // I'm not sure this is a good idea

	errorHandler.error("Failed to excute sql", sqle, 
ErrorCode.FLUSH_FAILURE);
      }
    }
  }
Comment 1 Mark Womack 2003-02-19 04:54:39 UTC
This is a duplicate of earlier reported bug #14827, which will be addressed in 
the v1.2.8 release.  If you are interested in improving JDBCAppender, I urge 
you to become involved with its development on the log4j-dev email list.  
Thanks.

*** This bug has been marked as a duplicate of 14827 ***