Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

memory leaking  RSS feed

 
Ranch Hand
Posts: 37
  • 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?
 
Bartender
Posts: 9521
12
Linux Mac OS X Windows
  • 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.
 
author
Sheriff
Posts: 23587
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 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
 
Ranch Hand
Posts: 1311
  • 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.
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • 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
 
Ranch Hand
Posts: 126
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!