Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OutOfMemoryError even when UndoManager limit is set to 0 #99

Open
pmouawad opened this issue Jan 23, 2015 · 2 comments
Open

OutOfMemoryError even when UndoManager limit is set to 0 #99

pmouawad opened this issue Jan 23, 2015 · 2 comments

Comments

@pmouawad
Copy link

Hi,
We are using RSyntaxTextArea and faced in the past this:
#19
So we implemented the proposed method.
We recently had a bug report:
https://issues.apache.org/bugzilla/show_bug.cgi?id=57440
As per comment of last 9 days we implemented a fix.

But it seems RUndoManager keeps piling up in org.fife.ui.rtextarea.RUndoManager$RCompoundEdit a huge number of javax.swing.text.AbstractDocument$DefaultDocumentEvent.

See screenshots:
screen shot 2015-01-23 at 09 09 37
screen shot 2015-01-23 at 09 10 07

See code:
https://github.com/apache/jmeter/blob/trunk/src/core/org/apache/jmeter/gui/util/JSyntaxTextArea.java

https://github.com/apache/jmeter/blob/trunk/src/core/org/apache/jmeter/gui/LoggerPanel.java

Thanks

@pmouawad
Copy link
Author

Hi,
I traced what is happening.
When we call this piece of code:
Document doc;
try {
doc = textArea.getDocument();
Element root = doc.getDefaultRootElement();
int lineCount = root.getElementCount();
if (lineCount>LOGGER_PANEL_MAX_LINES_COUNT) {
int end = root.getElement(lineCount-LOGGER_PANEL_MAX_LINES_COUNT-1).getEndOffset();
doc.remove(0, end);
}
doc.insertString(doc.getLength(), format.format(logEvent), null);
textArea.setCaretPosition(doc.getLength()-1);
} catch (BadLocationException e) {
// NOOP
}

doc.insertString ends up calling RUndoManager#startCompoundEdit which leads to OOM.
screen shot 2015-01-24 at 15 00 53

I am wondering why RUndoManager does this when limit is set to 0.
Seems to be the bug.

@bobbylight
Copy link
Owner

Looking back at old, unclosed threads...

It looks like setting the limit of undos to 0 actually disables the limit (this is in Swing's UndoManager class), so my suggestion way back when was way off-base.

I can think of two workarounds for you until a solution is put into RSTA:

  1. Set your undo limit to 1 instead of 0. As long as your editor is read-only, users should not be able to trigger undo actions, and RSTA's memory usage should not grow indefinitely.
  2. Create a subclass of RUndoManager, override methods to make it do nothing (perhaps undo(), redo(), and undoableEditHappened()), then create an RSyntaxTextArea subclass, overriding the createUndoManager() method to return your do-nothing implementation.

vlsi added a commit to vlsi/jmeter that referenced this issue Nov 4, 2021
There are two fixes:
1) undoManager.setLimit(0) -> setLimit(1) since (0) means "unlimited undo"
See bobbylight/RSyntaxTextArea#99

2) By default, JMeter adds undoManager to ALL text fields via Swing updateUI method,
so we need to explicitly uninstall it for the case when undo is not needed
vlsi added a commit to vlsi/jmeter that referenced this issue Nov 4, 2021
…or it)

There are two fixes:
1) undoManager.setLimit(0) -> setLimit(1) since (0) means "unlimited undo"
See bobbylight/RSyntaxTextArea#99

2) By default, JMeter adds undoManager to ALL text fields via Swing updateUI method,
so we need to explicitly uninstall it for the case when undo is not needed
vlsi added a commit to vlsi/jmeter that referenced this issue Nov 4, 2021
…or it)

There are two fixes:
1) undoManager.setLimit(0) -> setLimit(1) since (0) means "unlimited undo"
See bobbylight/RSyntaxTextArea#99

2) By default, JMeter adds undoManager to ALL text fields via Swing updateUI method,
so we need to explicitly uninstall it for the case when undo is not needed
vlsi added a commit to vlsi/jmeter that referenced this issue Nov 4, 2021
…or it)

There are two fixes:
1) undoManager.setLimit(0) -> setLimit(1) since (0) means "unlimited undo"
See bobbylight/RSyntaxTextArea#99

2) By default, JMeter adds undoManager to ALL text fields via Swing updateUI method,
so we need to explicitly uninstall it for the case when undo is not needed
vlsi added a commit to vlsi/jmeter that referenced this issue Nov 4, 2021
…or it)

There are two fixes:
1) undoManager.setLimit(0) -> setLimit(1) since (0) means "unlimited undo"
See bobbylight/RSyntaxTextArea#99

2) By default, JMeter adds undoManager to ALL text fields via Swing updateUI method,
so we need to explicitly uninstall it for the case when undo is not needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants