You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2003/02/12 15:58:31 UTC

DO NOT REPLY [Bug 16998] New: - JDBCAppender leaks memory

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16998>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16998

JDBCAppender leaks memory

           Summary: JDBCAppender leaks memory
           Product: Log4j
           Version: 1.2
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Appender
        AssignedTo: log4j-dev@jakarta.apache.org
        ReportedBy: Roland.S.Nygren@Telia.se


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);
      }
    }
  }

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org