Sunday, July 12, 2009

One of the major problems faced by C++ programmers is the memory leakage, which means allocating memory dynami

One of the major problems faced by C++ programmers is the memory leakage, which means allocating memory dynamically and not reclaiming it when it is no longer it is needed. However, in Java, there is no such problem as there is a garbage collector. What is it?

One of the major problems faced by C++ programmers is the memory leakage, which means allocating memory dynami
Most computer programs require memory to be allocated dynamically ie when the program is running. There are two approaches to giving memory to the program. Either the programmer manages it or lets the system (Language) handle it. There are advantages and disadvantages in both.





Usually a programmer is the best person to know when the program needs more memory or when it is no longer required and hence they are in control of when to do it. On the flip side they might allocate memory and 'forget' to deallocate the same resulting in what is called "memory leaks", where memory is requested from the system but lies unused.





The other approach is what Java has taken where the language semantics dictate when the memory is no longer used by the program and hence it can take a call on when to deallocate memory. However instead of deallocating small chunks of memory whenever it is not required, it typically accumulates such requests and deallocates at a 'suitable' time, when the system runs out of memory to allocate or some such scenario. This makes the life of the programmmer easy as he doesn't have to bother about "freeing" memory himself, but could lead to non-deterministic runtime behavior of the program. Hence this is not preferred in domains like Real-time programming, where the programs have to behave deterministically.
Reply:garbage collector is a part of java system, that keeps track of objects you allocate, and releases the memory when you are no longer using them. Does a pretty crappy job, if you ask me.


I'd put it quite the opposite way actually - on of the major problem of java programmers is not being able to control their own memory, like in normal rogramming languages.
Reply:Basically, the garbage collector deallocates memory used by objects when that object is no longer able to be reached by the running program. This happens periodically while the program is running, and may be called from within the program explicitly.
Reply:http://www-128.ibm.com/developerworks/ja...
Reply:My garbage collector comes on Thursdays. Does that count?

survey questions

No comments:

Post a Comment