Memory Analysis Best Practices Within Eclipse
Memory Analysis Best Practices Within Eclipse
Within Eclipse
Written by
Steven Haines
White Paper
© Copyright Quest® Software, Inc. 2008. All rights reserved.
This guide contains proprietary information, which is protected by copyright. The
software described in this guide is furnished under a software license or
nondisclosure agreement. This software may be used or copied only in accordance
with the terms of the applicable agreement. No part of this guide may be reproduced
or transmitted in any form or by any means, electronic or mechanical, including
photocopying and recording for any purpose other than the purchaser's personal use
without the written permission of Quest Software, Inc.
WARRANTY
TRADEMARKS
All trademarks and registered trademarks used in this guide are property of their
respective owners.
World Headquarters
5 Polaris Way
Aliso Viejo, CA 92656
www.quest.com
e-mail: [email protected]
U.S. and Canada: 949.754.8000
Please refer to our Web site for regional and international office information.
Updated—June 2008
CONTENTS
CONTENTS ......................................................................................... 1
ABSTRACT ......................................................................................... 2
INTRODUCTION ................................................................................. 3
STATE OF THE MARKET ........................................................................... 4
MEMORY ANALYSIS WITH ECLIPSE ................................................... 5
NATURE OF JAVA MEMORY ISSUES .............................................................. 5
MEMORY ANALYSIS REQUIREMENTS ............................................................ 6
SUMMARY .......................................................................................... 8
ABOUT THE AUTHOR .......................................................................... 9
REFERENCES ...................................................................................... 9
ABOUT QUEST SOFTWARE, INC. ...................................................... 10
CONTACTING QUEST SOFTWARE ............................................................... 10
CONTACTING QUEST SUPPORT ................................................................. 10
ABSTRACT
The performance of many enterprise Java applications can typically be poor,
forcing affected companies to pay the high price of lost sales and tarnished
reputations. Fortunately, proactive attention to the performance of an
application while it is being developed can eliminate most performance issues
before your customers ever see them. This paper presents a strategy for
identifying memory leaks in Java applications from the comfort of the Eclipse
Java Integrated Development Environment (IDE). You will learn how the Java
garbage collector works, the nature of memory leaks, and how to avoid
them. You will also learn how to configure the automated analysis of unit test
case memory usage inside Eclipse, while learning strategies for isolating and
resolving memory leaks. Lastly, I will explain how to regularly generate
memory profiles in a repeatable fashion. Because everything runs from inside
Eclipse, you can generate memory profiles and summary reports with the
click of a mouse once Eclipse is configured.
2
INTRODUCTION
Performance for many enterprise Java applications today is astonishingly
poor. There are many things that we can do to address this problem, both
proactively as well as reactively. Traditionally, organizations have ignored
performance concerns when developing their Java applications, and instead
they spend dollars in a reactive manner—troubleshooting performance issues
as they arise. Unfortunately, correcting a problem once an application has
been deployed to a production environment is expensive and time-
consuming, as illustrated in Figure 1.
3
State of the Market
The quality and performance of enterprise applications in our industry are
astonishingly poor, as illustrated by the following research analyst findings:
According to Forrester Research, nearly 85 percent of companies with
revenue of more than $1 billion reported incidents of significant
application performance problems.1 Survey respondents identified the
architecture and deployment as the primary causes of these
problems.2 Based on this survey, it seems that no matter how much
you tune your hardware and environment, application problems will
persist.
Infonetics Research found that medium-sized businesses (101 to 1,000
employees) are losing an average of one percent of their annual
revenues, or $867,000, to downtime. Application outages and
degradations are the biggest sources of downtime, costing these
companies $213,000 annually.3
The cost of outages and performance degradation can be calculated in
several ways, based on the type of application:
Business-to-consumer: a direct loss of sales revenue because of web
site abandonment and lack of consumer confidence
Business-to-business: a loss of credibility, which can eventually lead to
lost business partnerships
Internal applications: a loss of employee productivity
With respect to business-to-consumer applications, consider the typical
shopping pattern of modern-day consumers. They usually find an item at one
of the major retailers and then search for the best price online. In the end,
the prices do not usually vary more than five percent, so they choose a
vendor they trust within that range. However, if the vendor’s site is running
slow or makes finalizing the purchase too difficult, they simply move down
the list to the next preferred vendor. By and large, retailer loyalty has been
replaced by price competition and convenience. So even a minor site outage
could mean lost business.
In a business-to-business relationship, the stakes are much higher. Let’s say
you are one of several companies that sell widgets. If you have established a
relationship with a major retailer, the reliability and performance of your B2B
application is your livelihood. If the major retailer submits an order for
additional widgets and your application is unavailable or the order is lost, you
run the risk of losing the partnership—and the revenue. Continual application
problems mean lost accounts.
Slow or poorly performing internal applications can also impact the bottom
line. Employee productivity suffers when an application goes down or
responds slowly. More significantly, lost time can delay product delivery.
When that happens, your company can either delay the product release or
reduce the scope of the release to meet deadlines. Either option can lead to a
disaster.
4
MEMORY ANALYSIS WITH ECLIPSE
5
example, if you add an object to a collections class (an object container
found in the java.util package, such as ArrayList or HashMap) then the
collections class will maintain a reference to that object until you explicitly
tell the collections class to remove that reference. Consider the following
code:
public class MyClass {
7
SUMMARY
The performance of many enterprise Java applications is typically poor, but
through proactive means we can find performance problems as we build our
applications—when they are easy and inexpensive to fix. This paper
presented a strategy for identifying and resolving memory leaks in your
applications. With the help of a profiling tool that offers a certain level of
automation, you can be sure that performance tests are executed
consistently and in a reproducible fashion. Also, if you choose to adopt the
practice of using a profiler that can seamlessly integrate with your Eclipse
Java IDE, profiling your application code can be convenient enough for you to
execute on a regular basis. By adopting this strategy, you will be able to
write more efficient code and help the entire Java community reduce the
currently abysmal performance statistics.
8
ABOUT THE AUTHOR
Steven Haines is the founder and CEO of GeekCap, Inc., which provides
professional services, software solutions development, certification programs
and e-learning through formal online courses. Subjects such as Spring,
Hibernate, Google and Web Toolkit. Previously, Haines was the Java EE
Domain Expert at Quest Software, where he defined the expert rules and
views used to monitor the performance of enterprise Java applications and
application servers. During his tenure at Quest, Haines created a Java EE
performance-tuning professional services organization, which improved the
performance of and resolved critical production issues for many Fortune 500
companies. He is the author of Pro Java EE 5 Performance Management and
Optimization (Apress), Java 2 Primer Plus (Sams), and Java 2 From Scratch
(Que), and shares author credits on Java Web Services Unleashed. Haines is
the Java host on Pearson Education’s online IT resource, Informit.com, where
he posts weekly articles and blogs. He is a Java community editor on
InfoQ.com, where he posts weekly articles covering breaking news. Haines
has taught all facets of Java programming at the University of California,
Irvine, and at Learning Tree University. Look for his latest digital shortcut
book, Agile Java Development with Test-Driven Development and Continuous
Integration, this winter on Informit.com. Haines can be reached at
[email protected].
REFERENCES
1. Forrester, "Best Practices In Problem Management", June 23, 2004,
Jean-Pierre Garbani.
2. Network World, "New apps can be a real pain in the net", July 21,
2003, Denise Dubie.
9
ABOUT QUEST SOFTWARE, INC.
Quest Software, Inc., a leading enterprise systems management vendor,
delivers innovative products that help organizations get more performance
and productivity from their applications, databases, Windows infrastructure
and virtual environments. Through a deep expertise in IT operations and a
continued focus on what works best, Quest helps more than 90,000
customers worldwide meet higher expectations for enterprise IT. Quest’s
Foglight® application management solution unifies IT services with end users
and the business, resolves problems faster to reduce downtime, and lowers
the operating cost of managing applications. Quest Software can be found in
offices around the globe and at www.quest.com.
10