Memory Leaks using RSyntaxTextArea/AutoCompletion in JDialog

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Memory Leaks using RSyntaxTextArea/AutoCompletion in JDialog

Postby gehatg » Fri May 25, 2012 9:24 am

Hallo,

I have investigated this for a while and it seams that the Autocompletion#uninstall() method does not release all resources, and it results on a memory leak when used on a JDialog component.

To replicate the error:

1. Create a JDialog with a couple of (new RSynstaxTextAreas) in it.
2. Add a (new Autocompletion) to its constructor to it (doesnt matter the Provider)
3. Invoke uninstall before disposing and completely destroying the dialog
4. Do a System.gc() in your JFrame and see that the amount of memory increases at almost 700Kb every time that you run the JDialog
5. Run your JDialog around 20 times you will have an increase of 20Mbs that is a huge memory leak! Making RSyntaxArea unable to be used in dynamic JDialogs!

I have checked the Autocompletion code and it seams that you are unregistering some listeners is there anything you forgot that causes this memory leak?

Thanks
gehatg
 
Posts: 4
Joined: Fri May 25, 2012 9:07 am

Re: Memory Leaks using RSyntaxTextArea/AutoCompletion in JDi

Postby robert » Fri May 25, 2012 12:32 pm

There certainly could be a leak, so I will take a look, but also keep in mind that the JVM isn't required to immediately return all unused memory to the OS, even after a System.gc() call. Can you actually get an OutOfMemoryError if you open and close the JDialog enough times? You can set -Xmx=24m for example to speed up the test.

Also, are you using RSTALanguageSupport, and if so, what languages? Or are you just using the AutoComplete library? Just asking since the former installs additional listeners.
User avatar
robert
 
Posts: 798
Joined: Sat May 10, 2008 5:16 pm

Re: Memory Leaks using RSyntaxTextArea/AutoCompletion in JDi

Postby gehatg » Fri May 25, 2012 1:34 pm

Hallo Robert,

Yes I do get OutOfMemory errors, and I also found the memory leak after debuging your code all day and using JProfiler to find out what was happening.

The cause of error is the following code that you use inside Autocompletion class:

Code: Select all
      UIManager.addPropertyChangeListener(new PropertyChangeListener() {
         public void propertyChange(PropertyChangeEvent e) {
            String name = e.getPropertyName();
            if (name.equals("lookAndFeel")) {
               updateUI();
            }
         }
      });


Please comment this code out as all objects that refernce Autocompletion will never be garbage collected cause this property change listener is never beeing removed!

When are you planning to make a fix?

Thanks
gehatg
 
Posts: 4
Joined: Fri May 25, 2012 9:07 am

Re: Memory Leaks using RSyntaxTextArea/AutoCompletion in JDi

Postby gehatg » Fri May 25, 2012 1:38 pm

Also in next version is it possible to make AutoCompletion#isPopupVisible a public method? As It is critical in my code to now when to signal automatic precompilations.

Thanks
gehatg
 
Posts: 4
Joined: Fri May 25, 2012 9:07 am

Re: Memory Leaks using RSyntaxTextArea/AutoCompletion in JDi

Postby robert » Sat May 26, 2012 12:12 am

Check out the latest from SVN, I now remove the listener when you call uninstall() on the AutoCompletion, I believe that should clear up any leaks.

As for isPopupVisible(), what are you trying to accomplish exactly? Are you trying to parse the code to generate the completion list when the popup is made visible? That is a scenario I need to make simpler.
User avatar
robert
 
Posts: 798
Joined: Sat May 10, 2008 5:16 pm

Re: Memory Leaks using RSyntaxTextArea/AutoCompletion in JDi

Postby gehatg » Mon May 28, 2012 12:44 pm

What I am trying to do is to use RSyntaxTextArea for editing excel style expression language code using a custom TokenMaker.
I want to use it exactly like how you edit expression language in Excel (area after the F(x) label).

Everything would work great if isPopupVisible was public because I really need to check if the enter was pressed when the popup was visible or not.
If it was pressed when the popup was not visible this means that I have to parse and store the formula otherwise it was a selection from the popup.

I hope this helps.
gehatg
 
Posts: 4
Joined: Fri May 25, 2012 9:07 am

Re: Memory Leaks using RSyntaxTextArea/AutoCompletion in JDi

Postby robert » Tue May 29, 2012 3:35 am

Assuming you're getting a KeyEvent, does e.isConsumed() return true when the user selects a completion choice? If so, can you base your decision off of that? It sounds like your listener is getting executed first, so you may not be able to depend on this, but it's worth checking
User avatar
robert
 
Posts: 798
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 6 guests

cron