aspose file tools*
The moose likes Performance and the fly likes memory leaking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "memory leaking" Watch "memory leaking" New topic
Author

memory leaking

ajay verma
Ranch Hand

Joined: Dec 10, 2007
Posts: 37
how can i come to know about memory is leaking or not?
can you dictate me related one with the help of program?
and what is memory leaking?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8908
    
    8

The first clue one gets that they have a memory leak is that their application gets an OutOfMemoryError.
Here is an article about memory leaks, what causes them and how to resolve them.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18843
    
  40

Originally posted by ajay verma:
how can i come to know about memory is leaking or not?
can you dictate me related one with the help of program?
and what is memory leaking?


There is no simple answer here. In C/C++, a memory leak is defined as memory that has been malloc'ed (new'ed), and lost. All pointers to the memory are gone, which means that it is not possible to reclaim (free / delete) the memory. Yet, the program still thinks that it is in use.

In Java, the GC takes care of this. So it is not possible to have memory leaks due to setting references to null. However, it is possible to have memory leaks due to "forgotten" references. For example, you write a cache that is used for optimation purposes, but you forget that it uses a static hashmap somewhere. Even if you set all the references to null, this cache located in some static variable will always have a reference.

Now, if this code is part of a jar file, used by the company (and you are no longer with the company), it is highly unlikely that it will be found.


For me, I generally use a profiler to determine memory leaks. The profiler that I use provides a view into the heap -- I know what objects are in the heap, how many of them are there, and their average size. With this, you can determine which objects that are growing in the heap, which shouldn't be... this can be used as likely places to look for memory leaks.

The profiler that I use also provides views into resources, number of open sockets, open files, amount of memory used by which subsystem, etc. With this, you can tell if the system is leaking resources, which is also a sign of a memory leak.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Billy Tsai
Ranch Hand

Joined: May 23, 2003
Posts: 1304
can objects(local variables) be garbage collected in a private method before the method finishes?
I know the objects are put on the stack and become eligible for garbage collection after exiting the method but what if I need load large number of different objects into several different Array and perform different processing for these arrays(for loop) can I set the an array object to null immediately so its possible to be garbage collected
before loading another set of different objects into another array? or else the memory will all be used up in that method.


BEA 8.1 Certified Administrator, IBM Certified Solution Developer For XML 1.1 and Related Technologies, SCJP, SCWCD, SCBCD, SCDJWS, SCJD, SCEA,
Oracle Certified Master Java EE 5 Enterprise Architect
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12787
    
    5
I know the objects are put on the stack and become eligible for garbage collection after exiting the method


When talking about objects you MUST always be careful to distinquish between references and objects. References are on the stack, the JVM is managing the objects elsewhere.

GC is perfectly capable of recognizing that there are no more valid references to an object while still inside methods and before exiting the method.

For example variables declared inside code blocks of various kinds. You can experiment with this by coding a class with a System.out.print in the finalize method.

Bill
Raees Uzhunnan
Ranch Hand

Joined: Aug 15, 2002
Posts: 126
download and use a java profiler to find the memory leak. there are many profilers available for download

YourKit www.yourkit.com
Jprofiler www.ej-technologies.com
BEA mission control www.bea.com

all of these products give adequate evaluation license.

thanks
raees


Sun Certified Enterprise Architect
Java Technology Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: memory leaking