0

I have read that memory leak in C++ works different as compared to that in Java. I know automatic memory management takes care in Java. whereas, in C++ memory management is handled by the programmers. Any flaw in programming will make the small amounts of data improperly reclaimed or lost

On the other hand in Java we have unreferenced objects (also dead objects) once they have been used. And I realised that all unreferenced objects are unused objects. But there would be some unused objects which are referenced and Garbage collector fails to recognize them. That is what I read about memory leak in Java.

So my question here is: Both memory leak concepts are different different in C++ and Java. Please correct me if I am missing something.

Thanks !!

sri
  • 21
  • 1
  • 1
    You are essentially right. In Java, the Garbage Collector (eventually) deletes unreferenced objects, but holding references to objects which will not be used any more can lead to something similar as memory leaks. – J Fabian Meier Jun 30 '16 at 15:28
  • "Memory leak" is a very broad term, and there are different types of memory leaks. There are some types of memory leaks specific to C++ (e.g. allocated and non-released memory) or to Java (e.g. leaks produced by static references, when redeploying an application in a container) – Alex Shesterov Jun 30 '16 at 15:31
  • It's quite possible to force something like a memory leak in Java, see http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java However, the disputing comments on most answers should also help you understand why it's difficult to generate a 'pure' memory leak in Java – Jeutnarg Jun 30 '16 at 15:48
  • @Jeutnarg which is, as I forgot to mention, in direct contrast to C++, where it is very, very easy to generate a 'pure' memory leak – Jeutnarg Jun 30 '16 at 15:53
  • What exactly is your question? – davmac Jun 30 '16 at 16:37

0 Answers0