Memory leak analysis [message #103965] |
Mon, 09 July 2007 22:27  |
Eclipse User |
|
|
|
I am just trying out TPTP memory analysis with a small test program to see
how it works. When I run a basic memory analysis with the following
example, I don't see any correlation of the results that would actually
help me find the "problem" in this manufactured example.
The Memory Statistics show char[], byte[], short[] and int[] being the
largest numbers of instances. But there is no connection back to my test
code and I am surprised to no have java.lang.Integer even listed.
The Object References view also provides no more info, being similarly
flat and without any connection back in to my test code.
Contrast this with running the same code under Netbeans profiler and I get
a large number of java.lang.Integer objects and a stack trace to the
source.
Am I missing something? How do I actually get useful info out of the basic
memory analysis?
Thanks in advance... sample code follows.
package mt;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class MemTest {
private List hog = new ArrayList();
public MemTest()
{
}
public void doStuff()
{
Iterator iter = hog.iterator();
int i=0;
while (iter.hasNext())
{
i++;
iter.next();
}
System.out.println("count = "+i);
}
public void createStuff()
{
for (int i=0; i<100; i++)
{
hog.add(new Integer(i));
}
}
/**
* @param args
*/
public static void main(String[] args)
{
MemTest mt = new MemTest();
for (int i=0; i<100; i++)
{
mt.doStuff();
mt.createStuff();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
|
|
|
Re: Memory leak analysis [message #105664 is a reply to message #103965] |
Thu, 19 July 2007 02:27  |
Eclipse User |
|
|
|
Andrew Zahra wrote:
> I am just trying out TPTP memory analysis with a small test program to
> see how it works. When I run a basic memory analysis with the following
> example, I don't see any correlation of the results that would actually
> help me find the "problem" in this manufactured example.
>
> The Memory Statistics show char[], byte[], short[] and int[] being the
> largest numbers of instances. But there is no connection back to my test
> code and I am surprised to no have java.lang.Integer even listed.
>
> The Object References view also provides no more info, being similarly
> flat and without any connection back in to my test code.
>
> Contrast this with running the same code under Netbeans profiler and I
> get a large number of java.lang.Integer objects and a stack trace to the
> source.
>
> Am I missing something? How do I actually get useful info out of the
> basic memory analysis?
>
> Thanks in advance... sample code follows.
>
Hi Andrew,
Thank you for your interest in TPTP.
Have you tried the new Heap Profiler in TPTP 4.4? Although not as mature
as the Netbeans profiler, it provides accurate allocation details and
can trace allocations to their source (but without a full stack trace).
To use the new profiler:
1. Install Eclipse 3.3
2. Install TPTP 4.4 (latest patch, 4.4.0.1 is recommended)
3. Launch Eclipse with a Java 5 (or 6) JVM.
4. Configure a Heap Profiling session, double click the Memory Analysis
collector in the Monitor tab, and select the "Track Object Allocation
Sites" option.
Note that your example will not work properly with the default filter
set, as java.lang.* objects (e.g., Integer) are excluded by default), so
make sure you change this filter before starting to profile.
HTH,
Asaf
--
Asaf Yaffe
Eclipse TPTP Committer, JVMTI Profiler
|
|
|
Powered by
FUDForum. Page generated in 0.03591 seconds