20 October 2010
1 Memory DeAllocation-Garbage Collection in Java
Memory DeAllocation or Garbage Collection in Java
A major difficulty in dynamic memory allocation in C/C++ was that the programmer is responsible for de-allocating the dynamic memory at the right time. Even though experienced programmers can do this very well, beginners and average programmers often missed the statements for de-allocated which led to memory-leak in many systems.An object that is not referred by any reference variable will be removed from the memory by the garbage collector, this process is known as Garbage Collection
Garbage Collection is Automatically done by JVM, the Automatic Garbage Collection of Java de-allocates the dynamic memory automatically when this memory is no more used by the program. This relieves the programmer from the overhead of memory de-allocation.
If a reference variable is declared within a function, the reference is invalidated soon as the function call ends.
Programmer can explicitly set the reference variable to null to indicate that the referred object is no longer in use.
Primitive types are not objects and they cannot be assigned null.
Subscribe to:
Post Comments (Atom)
1 comments:
Nice article , you have covered topic in details with sample code and graphics, its indeed a topic which require a deeper understanding than many other java topics.
Javin
How Garbage collection works in Java
Please give your valuable comments.