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 40565 - Huge memory leak when rescanning tasks
Summary: Huge memory leak when rescanning tasks
Status: VERIFIED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Action Items (show other bugs)
Version: 3.x
Hardware: PC Linux
: P2 blocker (vote)
Assignee: tasklist-issues@contrib
URL:
Keywords: PERFORMANCE
Depends on: 40676
Blocks: 40229 40231
  Show dependency tree
 
Reported: 2004-02-27 13:49 UTC by Antonin Nebuzelsky
Modified: 2004-03-08 14:29 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
The backend test (1.92 KB, text/plain)
2004-02-27 16:42 UTC, _ pkuzel
Details
A patch that minimizes the leak 20times (967 bytes, patch)
2004-03-01 20:44 UTC, _ pkuzel
Details | Diff
Revised patch (no GC dependency) (1.82 KB, patch)
2004-03-02 12:51 UTC, _ pkuzel
Details | Diff
Addon patch eliminating exception caused by previous one. (3.18 KB, patch)
2004-03-03 13:12 UTC, _ pkuzel
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antonin Nebuzelsky 2004-02-27 13:49:02 UTC
Build 200402261900.

There is a memory leak when you repeatedly rescan
sources looking for tasks.

Steps to reproduce:

1) Start a trunk build with a clean userdir
2) Memory meter shows 13,0MB of used heap
(I always do several GCs before writing down the
number from memory meter)
3) Mount a local FS, e.g. openide/src
4) Wait for code completion DB to be created
5) Memory meter shows 13,9MB of used heap
6) Set the To Do limit in Options to 1000
7) Open To Do window
8) Search for tasks in openide/src FS
9) Memory meter shows 23,2MB of used heap
Part of heap listing from a profiler:
  [ name ] [ # instances] [ size in bytes]
   String           47363    1136712
   char[]           46212    8705864
   HashMap$Entry    41826    1003824
   <class>[]        29125    2118112
   ...
   CookieSet$R       3403      54448

10) close To Do window
11) open To Do window
12) Memory meter shows 20,3MB of used heap
13) rescan tasks in openide/src FS
14) Memory meter shows 28,7MB of used heap
Part of heap listing from a profiler:
  [ name ] [ # instances]
   String           47855
   char[]           46608
   HashMap$Entry    44297
   <class>[]        32952
   ...
   CookieSet$R       5687

15) rescan tasks in openide/src FS
16) Memory meter shows 33,8MB of used heap
Part of heap listing from a profiler:
  [ name ] [ # instances] [ size in bytes]
   String           48122    1154928
   char[]           46780   17360168
   HashMap$Entry    45815    1099560
   <class>[]        35496    2377568
   ...
   CookieSet$R       7207     115312
Comment 1 _ pkuzel 2004-02-27 15:04:50 UTC
Provided summary data are useless :-(. Could you please attach
allocation traces or even better back references to GC roots.

Thank you
Comment 2 _ pkuzel 2004-02-27 15:10:35 UTC
Possible culpit is docscan.SourceTasksView.resultsSnapshot cache
holding last search results and docscan.Cache class holding negative
results. These are necessary to meet responsiveness criteria.

Your use case just filled these caches. No memory consuption should
grow during further usage.
Comment 3 Antonin Nebuzelsky 2004-02-27 15:29:49 UTC
Sorry, I don't have enough time to resolve this issue. The provided
data is just to document the problem and its reproducibility.

Please, read the reproduction steps again! The memory usage grows and
grows and grows indefinitely with each repeat of the scan. This is
definitely not what we/you want! Right?
Comment 4 _ pkuzel 2004-02-27 15:56:42 UTC
I'm able to reproduce by refreshing again and again.
Comment 5 _ pkuzel 2004-02-27 16:41:09 UTC
I separated into two parts UI and backend. Backend test attached (no
memory leak observed).
Comment 6 _ pkuzel 2004-02-27 16:42:25 UTC
Created attachment 13713 [details]
The backend test
Comment 7 _ pkuzel 2004-02-27 16:57:17 UTC
Besides what is it <class>[]?
Comment 8 Antonin Nebuzelsky 2004-02-27 17:02:51 UTC
<class>[] is what JProfiler shows me. I don't know exactly what it
means. If you run OptimizeIt on this problem, it may show you some
different name for this item on the list of heap usage.

BTW, we agreed that this is rather a P2, not P1. Downgrading.
Anyway, this *must* be fixed to FCS.
Comment 9 _ pkuzel 2004-03-01 18:21:18 UTC
I created a test that detects some leaks in SourceTasksView.
/cvs/tasklist/docscan/test/perf/src/org/netbeans/modules/tasklist/docscan/HeapTest.java

Notifying you because the test also discovers that initial state is
not constant. Is it caused by hidden threading problems? Anyway it
complicates exact leak localization (and development of such (stable)
tests in general).
Comment 10 _ pkuzel 2004-03-01 20:44:16 UTC
Created attachment 13760 [details]
A patch that minimizes the leak 20times
Comment 11 _ pkuzel 2004-03-01 20:51:05 UTC
Ondra could you review please?
Comment 12 Milan Kubec 2004-03-02 08:47:51 UTC
Please, reporter, could you verify fixed issues. Thanks a lot.
Comment 13 Ondrej Rypacek 2004-03-02 09:17:23 UTC
Reviewed the fix - it looks fine.
Comment 14 _ pkuzel 2004-03-02 09:57:14 UTC
I think I discovered root cause, issue #40676.
Comment 15 _ pkuzel 2004-03-02 12:51:17 UTC
Created attachment 13770 [details]
Revised patch (no GC dependency)
Comment 16 _ pkuzel 2004-03-02 12:55:39 UTC
We cannot deliver clean solution of issue #40676 in 3.6 timeframe.

However there exists another substitute working for this case. It has
advantage over previous patch that it does not depend on GC (therefore
being more deterministics).

Could you review, please?
Comment 17 Ondrej Rypacek 2004-03-02 13:21:35 UTC
reviewed, looks good too.
Comment 18 _ pkuzel 2004-03-02 14:17:53 UTC
Remaining leak estimate:

320b per refresh + 20b per refresh per TODO.
For 1000 TODOs it could mean 20320b leak per refresh.

Just estimate, actual numbers vary (depends on unknown conditions).
Comment 19 _ pkuzel 2004-03-03 10:18:47 UTC
Fix causes threading problems:

ava.lang.IndexOutOfBoundsException: Index: 3, Size: 3
	at java.util.ArrayList.RangeCheck(ArrayList.java:507)
	at java.util.ArrayList.get(ArrayList.java:324)
	at
org.netbeans.modules.tasklist.core.TaskList.fireStructureChanged(TaskList.java:279)
	at
org.netbeans.modules.tasklist.core.Task.fireStructureChanged(Task.java:180)
	at org.netbeans.modules.tasklist.core.Task.clear(Task.java:99)
	at org.netbeans.modules.tasklist.core.TaskList.clear(TaskList.java:324)
	at
org.netbeans.modules.tasklist.docscan.SourceTasksView.handleRefresh(SourceTasksView.java:1075)
Comment 20 _ pkuzel 2004-03-03 10:49:41 UTC
It's not threading, TaskChildren$Monitor fires destroyed event that in
turn unregister all TaskNode$Monitor listeners (from same thread so it
pass all barriers) and iteration fails.
Comment 21 _ pkuzel 2004-03-03 13:12:37 UTC
Created attachment 13791 [details]
Addon patch eliminating exception caused by previous one.
Comment 22 _ pkuzel 2004-03-03 13:23:12 UTC
40565-leak2.patch & leak-l2.patch gives optimal results.

I noticed that remaining leak can be eliminated by user action. Click
on current file and back to selected folder. Memory meter goes down. 

This operation nulls background field that keeps reference to scanned
dataobjects. There is no event allowing to do it programatically.
Comment 23 Antonin Nebuzelsky 2004-03-03 13:27:09 UTC
Petr, when are you going to integrate the fixes to trunk and to
release36 branch? I will verify it when its there...
Comment 24 Antonin Nebuzelsky 2004-03-04 10:47:21 UTC
Verified in trunk. The huge memory leak is gone.
You can integrate to release36.
THX.
Comment 25 _ pkuzel 2004-03-04 11:00:47 UTC
Reviewers notified.
Comment 26 Ondrej Rypacek 2004-03-04 11:05:22 UTC
reviewed also the last patch. 
Comment 27 _ pkuzel 2004-03-05 17:17:06 UTC
backported to release36. 
Comment 28 Antonin Nebuzelsky 2004-03-08 14:29:14 UTC
Verified in release36 branch, build 200403071830.