• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

memory leaking

 
ajay verma
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Billy Tsai
Ranch Hand
Posts: 1304
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 126
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic