Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi Guys & Gals,
My manager the other day said to me that Java as a language
is more suited for small to mid size applications when taking
into concern Javas approach towards garbage collection.
He noted that Java basically holds a heap of objects used and
when that heap has reached its max size the thread starts to
inspect each individual object w/i the heap to see if it
should be discarded. Being this, he says that due to the time
it would take to scan through larger sized heaps, itsbetter
for smaller or mid-sized apps.

I knew I couldnt reply by askin him to forcefully start the
garbage collection thread n times, since this is unreliable.
So, what are some other alternatives. Ive heard mumblings of
"finalize", and others have mentioned something called
"weak reference". Could someone possibly help me here. I have
done a good amount of research and Id like to be able to
reply him constructively ya know?

Thanks
 
Apu Nahasapeemapetilon
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

He noted that Java basically holds a heap of objects used and
when that heap has reached its max size the thread starts to
inspect each individual object w/i the heap to see if it
should be discarded. Being this, he says that due to the time
it would take to scan through larger sized heaps, itsbetter
for smaller or mid-sized apps.

One question, how does the interpreter know what size to set the heap? If a larger app has a bigger heap, how does this happen without explicitly setting this value on the interpreter command line?
Additionally, the garbage collector is supposedly a low priority thread, thus if other threads need something they will supercede the gc thread. Therefore the contention that my program will slow down whilst waiting for the GC to search thru the heap, seems a little silly.
I don't claim to fully understand Garbage Collection as I have seen very inconsistent results. I do know that coding style can have a profound effect on GC.
Ask your manager a simple question. Would they prefer a large program with memory leaks (because someone forgot to clean up) or a large program with automatic garbage collection? Garbage collection will eventually occur, memory leaks require outside assistance to reclaim that memory. Java is slow due to its interpreted nature, not because of GC.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic