6 Replies - 372 Views - Last Post: 29 July 2011 - 07:03 AM Rate Topic: -----

#1 ipushmycar  Icon User is offline

  • D.I.C Regular

Reputation: 86
  • View blog
  • Posts: 390
  • Joined: 29-August 10

Java Garbage Collector

Posted 29 July 2011 - 06:39 AM

Since Java works in a VM is there ever a chance for a memory leak, dangling pointer, etc that would not be fixed when the program quit? I was interviewing last month and the interviewer said there was but I cannot think or find any that fit that case. Maybe he or I misunderstood what the other was saying, this man was extremely smart.

Thanks,
Is This A Good Question/Topic? 0
  • +

Replies To: Java Garbage Collector

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10814
  • View blog
  • Posts: 40,314
  • Joined: 27-December 08

Re: Java Garbage Collector

Posted 29 July 2011 - 06:42 AM

If the program uses too much memory, you can get an OutOfMemoryError. Once an object has no variables pointing to it, then it will be garbage collected. This is most likely what your interviewer was referring to. It's different than when talking about memory management in a more C/C++ context.
Was This Post Helpful? 1
  • +
  • -

#3 ipushmycar  Icon User is offline

  • D.I.C Regular

Reputation: 86
  • View blog
  • Posts: 390
  • Joined: 29-August 10

Re: Java Garbage Collector

Posted 29 July 2011 - 06:45 AM

Does each Java VM ask for a certain amount of memory before it is run then if it exceeds that amount throws the error? What is too much memory?
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10814
  • View blog
  • Posts: 40,314
  • Joined: 27-December 08

Re: Java Garbage Collector

Posted 29 July 2011 - 06:53 AM

You can manually allocate the heap size for the JVM. There are very few instances where you would really need to use more memory. I recall pbl saying once how he had to load thousands of records from a database into memory, then call System.gc() to run the garbage collector. Note that System.gc() attempts to clean up, but does not make any guarantees as to how much can or will be garbage collected. Chances are, if you're going out of memory, there is a more efficient way of doing what you want to do.
Was This Post Helpful? 1
  • +
  • -

#5 ipushmycar  Icon User is offline

  • D.I.C Regular

Reputation: 86
  • View blog
  • Posts: 390
  • Joined: 29-August 10

Re: Java Garbage Collector

Posted 29 July 2011 - 06:58 AM

I see. Maybe one should be made for you, If macosxnerd101, a man of great intelligence, is ONE OF your DIC's Idol, then put this in your signature to show your support!

This post has been edited by ipushmycar: 29 July 2011 - 06:59 AM

Was This Post Helpful? 1
  • +
  • -

#6 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2069
  • View blog
  • Posts: 4,307
  • Joined: 11-December 07

Re: Java Garbage Collector

Posted 29 July 2011 - 07:00 AM

The only way I can see that happening is if you execute native code from Java.
Was This Post Helpful? 1
  • +
  • -

#7 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10814
  • View blog
  • Posts: 40,314
  • Joined: 27-December 08

Re: Java Garbage Collector

Posted 29 July 2011 - 07:03 AM

Try generating the number of partitions for 100 using recursion and memorization. You will get an OutOfMemoryError before you reach 70. :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1