Subscribe today. Visit www.SAPinsideronline.com.
This article appeared in the Oct
n
Nov
n
Dec 2008 issue of
SAP Insider
and appears here with
permission from the publisher, Wellesley Information Services (WIS), www.WISpubs.com.
Memory is a critical resource, but some developers
still underestimate its value. The cost of memory
dominates the price of today’s servers — in general,
approximately 80% of hardware costs are attributed
to memory. Yet even when developers work to use
memory efficiently, the problem of undetected mem-
ory leaks often remains.
Memory leaks occur during long-lasting stateful
sessions (when a series of business objects is pro-
cessed consecutively); memory is occupied, but not
freed, once it is no longer needed. This all-too-
common problem results in high memory consump-
tion, tying up memory so that other users or programs
can’t use it.
In my previous Performance & Data Management
Corner column, I described a few options for solving
memory leaks on software architecture and pro-
gramming levels.
1
Now I’d like to familiarize
you with a tool that will allow you to analyze those
memory leaks — and ultimately eliminate them. This
tool is the ABAP Memory Inspector.
2
Before we dive into ABAP Memory Inspector’s
functionality and how to use it, let’s investigate some
familiar SAP tools that developers can employ to find
and identify user sessions with high memory usage,
the main hiding places for memory leaks.
Identify Potential Memory Problems
For developers, the first step to finding and stopping
memory leaks is to take advantage of some of the
transactions that SAP NetWeaver offers:
1
See “What You Don’t Know About Memory Can Hurt You: A (Re)introduction
to Efficient Memory Computing for Programmers and Developers” in the
October-December 2007 issue of
SAP Insider
(www.SAPinsideronline.com).
2
For a detailed introduction to ABAP Memory Inspector, see “Analyze
Memory-Related Problems in Your ABAP Programs in Less Time and
with Less Effort Using the ABAP Memory Inspector” in the November/
December 2004 issue of
SAP Professional Journal
(www.SAPpro.com).
SM04 (User session memory list): To look for
memory leaks, you need to monitor memory
consumption while several consecutive business
objects are processed within the same user session.
Transaction SM04 shows the current memory
usage of a user session. SM04 is ideal for online,
real-time monitoring. For example, you can easily
monitor online the memory growth of a long-
running dialog transaction or batch job (see sidebar
for more information about using SM04).
STAD (SAP Workload: Business Transaction Analysis):
STAD is ideal for monitoring the resource consump-
tion of a transaction after processing has completed.
To find the maximum level of memory consumption
of a dialog transaction or a batch job after it has
finished, check the statistical records — which are
recorded by default — in the SAP Workload Monitor
using the STAD transaction. Once you enter filter
criteria (your user name, for instance), you’ll see a
list of the dialog steps you processed. This list con-
tains a “Memory Used (kB)” column, which shows
the value of the memory consumed at the point in
time when the dialog step finished processing.
Use the ABAP Memory Inspector to
Analyze the Problem
Once you have used these tools to pinpoint the source
of your memory problem, you can further analyze
the problem with ABAP Memory Inspector by taking
snapshots of the memory usage of a user session.
3
To find memory leaks in the ABAP virtual machine
(VM), take two memory snapshots at different times
— for example, one after the n
th
purchase order has
3
To be more precise, this snapshot is of a single internal session, which is
what a user session typically consists of. Though the ABAP language
keywords CALL TRANSACTION and SUBMIT REPORT create a stack of
internal sessions, ABAP Memory Inspector only captures one internal
session of this stack per snapshot.
A Developer’s Guide to Protecting Memory
Detect and Eliminate Damaging Memory Leaks with ABAP Memory Inspector
Winfried Schleier (winfried.
schleier@sap.com) studied
physics at the Friedrich-
Alexander University of Erlangen-
Nuremberg, Germany, and
received his Ph.D. in computa-
tional physics. Winfried joined
SAP AG in 1994 and has been
a member of the Performance,
Data Management, and Scalability
team since its inception. His areas
of responsibility are performance,
benchmarking, and sizing of
different SAP solutions. Currently
Winfried is concentrating on
methodologies and tools for
memory optimization in the
ABAP VM.
|Performance & Data Management Corner
Wi nf ri e d Schl e ie r, S AP AG
4 NOTE!