This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 57565 - Repetitive opening and closing an HTML file leaves a memory leak
Summary: Repetitive opening and closing an HTML file leaves a memory leak
Status: CLOSED FIXED
Alias: None
Product: web
Classification: Unclassified
Component: HTML Editor (show other bugs)
Version: 4.x
Hardware: All All
: P3 blocker (vote)
Assignee: Marek Fukala
URL:
Keywords: PERFORMANCE
Depends on:
Blocks:
 
Reported: 2005-04-06 21:17 UTC by Antonin Nebuzelsky
Modified: 2009-05-18 10:45 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
3 times opened the html files (69.62 KB, image/png)
2005-04-06 21:18 UTC, Antonin Nebuzelsky
Details
4 times opened the html files (69.89 KB, image/png)
2005-04-06 21:19 UTC, Antonin Nebuzelsky
Details
DataEditorSupport$2 reference graph (84.13 KB, image/png)
2005-04-07 16:17 UTC, Antonin Nebuzelsky
Details
The diff of the fix. (1.13 KB, text/plain)
2005-04-14 10:48 UTC, Marek Fukala
Details
The references graph of the leak (24.75 KB, image/png)
2005-04-14 10:49 UTC, Marek Fukala
Details
A screenshot of JProfiler class moditor after opening/closing some HTML files in IDE with the fix (78.26 KB, image/png)
2005-04-14 10:51 UTC, Marek Fukala
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Antonin Nebuzelsky 2005-04-06 21:17:05 UTC
See the two attached screenshots of OptimizeIt window showing differences of
number of instances for 3 openings and 4 openings of four html files.
Comment 1 Antonin Nebuzelsky 2005-04-06 21:18:48 UTC
Created attachment 21430 [details]
3 times opened the html files
Comment 2 Antonin Nebuzelsky 2005-04-06 21:19:52 UTC
Created attachment 21431 [details]
4 times opened the html files
Comment 3 Antonin Nebuzelsky 2005-04-07 16:16:30 UTC
DataEditorSupport$2 seems to be the important instance leaking. Other leaking
instances seem to be connected to it...
Comment 4 Antonin Nebuzelsky 2005-04-07 16:17:20 UTC
Created attachment 21460 [details]
DataEditorSupport$2 reference graph
Comment 5 Antonin Nebuzelsky 2005-04-12 14:09:23 UTC
Marku, any progress on this? No more than four days to solve this in 4.1!
Comment 6 Marek Fukala 2005-04-12 14:12:35 UTC
I am working on this today...
Comment 7 Marek Fukala 2005-04-14 10:47:43 UTC
There is several independent memory leaks after opening / closing an HTML file.
Some of the leaks are not HTML file specific and happens likely for every
DataObjects (I tried java, JSP, html). They are:

org.openide.util.WeakListenerImpl$ListenerReference	 
org.openide.util.WeakListenerImpl$PropertyChange	 
org.openide.util.WeakListenerImpl$ProxyListener	 
org.openide.loaders.DataShadow$DSWeakReference	 
org.openide.loaders.DataShadow$OrigL

Certain number of these instancies is created and remains allocated after each
file opening/closing. I tried to investigate what is the problem, but I digged
into code which I have no clear idea how it works - most of the incoming
references are from lookups. I suggest the performance team to investigate this
and possibly file a bug against core or similar module.

Second group of leaking objects are following classes:
org.openide.text.DataEditorSupport$1
org.openide.text.DataEditorSupport$EnvListener
org.openide.util.lookup.InstanceContent
org.openide.util.lookup.AbstractLookup
org.openide.util.lookup.ArrayStorage

Certain number of objects of theses classes (~ 3) are created for each HTML file
opening /closing. They are not leaking for any other DOs I tried. There is a
circullar references path among most of these instancies (I will attach a
simplied reference graph to this issue). 

The code which is IMO responsible for the leak is DataEditorSupport$1 - an
anonymous class created in DataEditorSupport.createLookup:636 - property change
listener listening on changes of DataObject and updating an instancies lookup.
The lookup contains an instance which references the DataObject. 

So I fixed this by adding a weak property change listener to the dataobject. 

I have tested the fix and it seems to work correctly - the instancies are not
leaking and nothing else is broken.

---
fixed in trunk - I would like to kindly ask Jarda and Mila to review the fix and
Tonda to verify whether the leak is gone.
---

diff is attached.

Checking in DataEditorSupport.java;
/cvs/openide/loaders/src/org/openide/text/DataEditorSupport.java,v  <-- 
DataEditorSupport.java
new revision: 1.21; previous revision: 1.20
done
Comment 8 Marek Fukala 2005-04-14 10:48:12 UTC
Created attachment 21644 [details]
The diff of the fix.
Comment 9 Marek Fukala 2005-04-14 10:49:50 UTC
Created attachment 21645 [details]
The references graph of the leak
Comment 10 Marek Fukala 2005-04-14 10:51:43 UTC
Created attachment 21646 [details]
A screenshot of JProfiler class moditor after opening/closing some HTML files in IDE with the fix
Comment 11 Antonin Nebuzelsky 2005-04-14 14:17:45 UTC
Verified that the leak caused by DataEditorSupport$1 and including the lookups
is gone.
Comment 12 Marek Fukala 2005-04-14 14:46:02 UTC
forgot to mark as fixed (in trunk).
Comment 13 Miloslav Metelka 2005-04-14 14:52:30 UTC
The diff seems safe to me. The property change listener being added is never
removed which is a flaw that your patch seems to fix.
I agree with the integration.
Comment 14 Jaroslav Tulach 2005-04-14 14:54:10 UTC
"#57565: Adding the missing test to mfukala's commit" 
Checking in unit/src/org/openide/text/DataEditorSupportTest.java; 
/cvs/openide/loaders/test/unit/src/org/openide/text/DataEditorSupportTest.java,v  
<--  DataEditorSupportTest.java 
new revision: 1.2; previous revision: 1.1 
 
Comment 15 Jaroslav Tulach 2005-04-14 14:57:24 UTC
1. I've reproduced the described problem by the just commited test. It fails 
before Marek's patch and works now. So far so good. 
 
2. Please do not commit to org.openide.text without tests next time. The code 
is fragile and by checking in not enough justified code we just will not 
improve the maintanance of the package. So please, next time write the test 
first. 
 
3. I'd like to question this to be P2 bug. Imho its has much lower priority 
and as such it does not need to go to release41. But that is just minor 
comment. 
Comment 16 Petr Jiricka 2005-04-14 15:17:15 UTC
> So please, next time write the test first.

Or, just attach the patch, reassign to openide and let the owner check it in
with a test - after all, this is really an openide bug.

> I'd like to question this to be P2 bug. Imho its has much lower priority 
> and as such it does not need to go to release41.

I agree, especially given the size of the leaked memory. Tondo, what's your opinion?
Comment 17 Antonin Nebuzelsky 2005-04-14 15:27:02 UTC
>> I'd like to question this to be P2 bug. Imho its has much lower priority 
>> and as such it does not need to go to release41.

> I agree, especially given the size of the leaked memory. Tondo,
> what's your opinion?

Given the size of the leak, I don't insist on putting the fix at this last
moment in release41. Feel free to downgrade this to P3.
Comment 18 Marek Fukala 2005-04-14 16:25:42 UTC
I have talked offline about the fix with Jarda and Tonda, and both are OK with
integrating the fix into release41. Since the fix of the leak is safe, we have
test for it, it is verified and reviewed I will integrate the fix to 41.
Comment 19 Marek Fukala 2005-04-14 16:27:31 UTC
fixed in release41 branch

Checking in DataEditorSupport.java;
/cvs/openide/loaders/src/org/openide/text/DataEditorSupport.java,v  <-- 
DataEditorSupport.java
new revision: 1.20.4.1; previous revision: 1.20
done
Comment 20 Marek Fukala 2005-04-15 05:43:28 UTC
commited Jarda's test for the fix to release41 branch as well

Checking in DataEditorSupportTest.java;
/cvs/openide/loaders/test/unit/src/org/openide/text/DataEditorSupportTest.java,v
 <--  DataEditorSupportTest.java
new revision: 1.1.24.1; previous revision: 1.1
done
Comment 21 Jaroslav Tulach 2005-04-15 09:29:33 UTC
I think we have a problem: 
 
org.openide.text.AnnotationProviderTest start to fail randomly (twice from 
seven runs) yesterday on build 200504141800 and 200504142205. 
 
I believe it is related to this fix and should be resolved. 
Comment 22 zikmund 2005-04-15 09:45:50 UTC
I prefer remove the fix from release41 branch and downgrade the bug to P3 as
Tonda suggested.
Comment 23 Marek Fukala 2005-04-15 09:48:32 UTC
Jarda will check whether the test it OK and put an update into this issue. IMO
the fix is correct, maybe it revealed another bug?! I will revert the commit in
release41 if Jarda confirms that the fix caused the test failure.
Comment 24 Marek Fukala 2005-04-15 10:14:12 UTC
According to Jarda's findings the fix is really not safe so removed it from
release41 branch. The leak is not so horrible so I will also downgrade the issue
to P3. 

Checking in DataEditorSupport.java;
/cvs/openide/loaders/src/org/openide/text/DataEditorSupport.java,v  <-- 
DataEditorSupport.java
new revision: 1.20.4.2; previous revision: 1.20.4.1
done
Comment 25 Jaroslav Tulach 2005-04-15 10:29:22 UTC
"#57565: Additional changes. We managed to allow GC of the Lookup yesterday, 
today we prevent it to be GCed immediatelly" 
 
Checking in loaders/src/org/openide/text/DataEditorSupport.java; 
/cvs/openide/loaders/src/org/openide/text/DataEditorSupport.java,v  <--  
DataEditorSupport.java 
new revision: 1.22; previous revision: 1.21 
done 
Checking in test/unit/src/org/openide/text/AnnotationProviderTest.java; 
/cvs/openide/test/unit/src/org/openide/text/AnnotationProviderTest.java,v  <--  
AnnotationProviderTest.java 
new revision: 1.4; previous revision: 1.3 
 
Comment 26 Jaroslav Tulach 2005-04-15 10:30:39 UTC
I'd like to emphatize two things: 
 
1. when doing change in org.openide.text, write a test 
2. when doing any change in openide, please run existing tests before commit 
 
that way we prevent mistakes like this as the AnnotationProviderTest failure 
would be (very likely) discovered sooner. 
Comment 27 Jaroslav Tulach 2005-04-19 09:38:53 UTC
We have new failure and its log. 
Comment 28 Jaroslav Tulach 2005-04-19 09:39:21 UTC
Opps wrong issue. I am sorry. 
Comment 29 zikmund 2005-07-13 16:15:31 UTC
v