blob: a55183d5f2b4e74cab40794d6abaa81ce98561c9 [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= Memory Leaks need to be eliminated to Improve NetBeans Fitness
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:syntax: true
:description: Memory Leaks need to be eliminated to Improve NetBeans Fitness
:icons: font
:source-highlighter: pygments
:toc: left
:toc-title:
:toclevels: 5
:experimental:
Memory leaks seem to be one area not well covered by automated test yet. That
shall change, especially as it does not require any major changes into the
infrastructure. Our current infrastructure
link:http://openide.netbeans.org/tutorial/test-patterns.html#memory[assertGC]
with cooperation of JUnit or Jemmy/Jelly tests is good enough to allow us to
write reliable tests looking memory leaks up, providing enough info to easily
fix them and preventing their re-appearance in the system.
link:http://openide.netbeans.org/issues/show_bug.cgi?id=121855[issue 121855] or
proposal for reuse of link:FitnessViaTimersCounter.asciidoc[timers/counters]
infrastructure demonstrates the initial attempts in this area.
Based on that work, this page provides a how-to tutorial of using our *Memory
Leak Testing Infrastructure*.
[[Who_should_do_what]]
== Who should do what?
It is unlikely to expect that other teams are going to write memory leak tests
and that they will continuously look for memory leaks in their code. We need
the performance team to write the tests and moreover
write them in a way that can discover errors in foreign code. This requires
combination of good imagination and of integration testing, however issue
link:http://openide.netbeans.org/issues/show_bug.cgi?id=121855[issue 121855]
shows that this is possible in principle.
The *Memory Leak Testing Infrastructure* was created and is currently maintained by Jaroslav Tulach.
The link:FitnessViaTimersCounter.asciidoc[probes] into production code shall be
insert written by engineers that create the tests and either integrated
directly, or via a patch submitted into issuezilla. The second approach needs a
bit of presure on the module owner, so the patch is integrated in timely
manner.
The set of tests, verifying that basic create, open, edit, compile, run, close
operations on various project types is written by Performance QE team.
[[How_to_write_memory_leak_test]]
== How to write memory leak test?
* Well, basically write any regular test that verifies some functionality.
* Make sure there is a link:FitnessViaTimersCounter.asciidoc[probe] inside of the tested code that reports instances that can cause memory leaks
[source,diff]
----
File [Changed]: ProjectManager.java
Url: http://projects.netbeans.org/source/browse/projects/projectapi/src/org/netbeans/api/project/ProjectManager.java?r1=1.38&r2=1.39
Delta lines: +9 -1
-------------------
--- ProjectManager.java 26 Sep 2007 21:04:26 -0000 1.38
+++ ProjectManager.java 14 Dec 2007 16:11:26 -0000 1.39
@@ -85,6 +87,8 @@
// XXX change listeners?
private static final Logger LOG = Logger.getLogger(ProjectManager.class.getName());
+ /** logger for timers/counters */
+ private static final Logger TIMERS = Logger.getLogger("TIMER.projects"); // NOI18N
private static final Lookup.Result<ProjectFactory> factories =
Lookup.getDefault().lookupResult(ProjectFactory.class);
@@ -347,7 +351,11 @@
for (ProjectFactory factory : factories.allInstances()) {
Project p = factory.loadProject(dir, state);
if (p != null) {
+ if (TIMERS.isLoggable(Level.FINE)) {
+ LogRecord rec = new LogRecord(Level.FINE, "Project"); // NOI18N
+ rec.setParameters(new Object[] { p });
+ TIMERS.log(rec);
+ }
proj2Factory.put(p, factory);
state.attach(p);
return p;
----
* Before your test starts, initialize the memory leak tracking infrastructure
[source,java]
----
org.netbeans.junit.Log.enableInstances(Logger.getLogger("TIMER"), "Project", Level.FINEST);
----
* When your test is about to finish, assert that all collected instances can be GCed
[source,java]
----
org.netbeans.junit.Log.assertInstances("Some instances of Project not GCed");
----
That is all. Enjoy writing your memory leaks tests!
[[What_to_do_when_you_find_a_memory_leak]]
== What to do when you find a memory leak?
Report an error just like
link:http://www.netbeans.org/issues/show_bug.cgi?id=124040[124040] or
link:http://www.netbeans.org/issues/show_bug.cgi?id=124038[124038] or
link:http://www.netbeans.org/issues/show_bug.cgi?id=124042[124042].
Add
*PERFORMANCE* and *TEST* keywords to the issue and into status whiteboard added
*perfleak* word, that way we will be able to list all leaks fixed in 6.1 time
frame.
[NOTE]
====
The content in this page was kindly donated by Oracle Corp. to the
Apache Software Foundation.
This page was exported from link:http://wiki.netbeans.org/FitnessMemoryLeaks[http://wiki.netbeans.org/FitnessMemoryLeaks] ,
that was last modified by NetBeans user Tpavek
on 2010-02-18T17:42:56Z.
This document was automatically converted to the AsciiDoc format on 2020-03-15, and needs to be reviewed.
====