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=25086>.
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=25086

OutOfMemory error leads to confusing error in XmlLogger





------- Additional Comments From [EMAIL PROTECTED]  2004-02-09 07:16 -------
Running Ant from Cruisecontrol(http://cruisecontrol.sourceforge.net/) often
gives OOM because of the XmlLogger. 

I checked the implementation of the logger and observed the followings:
 - at each target/task starting event a corresponding TimedElement instance is
put in the tasks/targets hashtables
 - at each target/task finished event the TimedElement instance is looked up,
its and its corresponding "element"(org.w3c.dom.Element) field is completed.

I think, that at the target/task finished events, that is, targetFinished(...),
taskFinished(...) methods, after all relevant information has been extracted
from the timedElement, this can be removed from the tasks or target hashtables.
After removing it and setting explicitely the instance to null, we make it
eligible for GC.

Here is the patch: the lines marked /* newly added */ represent the changes.

 public void taskFinished(BuildEvent event) {
        Task task = event.getTask();
        TimedElement taskElement = (TimedElement) tasks.get(task);
        if (taskElement != null) {
            long totalTime = System.currentTimeMillis() - taskElement.startTime;
            taskElement.element.setAttribute(TIME_ATTR,
                    DefaultLogger.formatTime(totalTime));
            Target target = task.getOwningTarget();
            TimedElement targetElement = null;
            if (target != null) {
                targetElement = (TimedElement) targets.get(target);
            }
            if (targetElement == null) {
                buildElement.element.appendChild(taskElement.element);
            } else {
                targetElement.element.appendChild(taskElement.element);
            }
            Stack threadStack = getStack();
            if (!threadStack.empty()) {
                TimedElement poppedStack = (TimedElement) threadStack.pop();
                if (poppedStack != taskElement) {
                    throw new RuntimeException("Mismatch - popped element = "
                            + poppedStack.element + " finished task element = "
                            + taskElement.element);
                }
            }
            tasks.remove(task); /* newly added */
            task = null;        /* newly added */  
        }
    }

public void targetFinished(BuildEvent event) {
        Target target = event.getTarget();
        TimedElement targetElement = (TimedElement) targets.get(target);
        if (targetElement != null) {
            long totalTime
                    = System.currentTimeMillis() - targetElement.startTime;
            targetElement.element.setAttribute(TIME_ATTR,
                    DefaultLogger.formatTime(totalTime));

            TimedElement parentElement = null;
            Stack threadStack = getStack();
            if (!threadStack.empty()) {
                TimedElement poppedStack = (TimedElement) threadStack.pop();
                if (poppedStack != targetElement) {
                    throw new RuntimeException("Mismatch - popped element = "
                            + poppedStack.element
                            + " finished target element = "
                            + targetElement.element);
                }
                if (!threadStack.empty()) {
                    parentElement = (TimedElement) threadStack.peek();
                }
            }
            if (parentElement == null) {
                buildElement.element.appendChild(targetElement.element);
            } else {
                parentElement.element.appendChild(targetElement.element);
            }
         targets.remove(target); /* newly added */
         target = null;  /* newly added */
        }
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to