• Post Reply Bookmark Topic Watch Topic
  • New Topic

About gc  RSS feed

 
amit bhadre
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How we come to know that object is Garbej collected? But i know runtime.gc take care but programatically how can we come to know with garanty...?
 
Jeremy Tartaglia
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're asking "how will we know if an object is eliminated by the garbage collector", the answer is, quite frankly, that you won't. Garbage collectors work like this:

1) Unmark all resources
2) Check every variable in use
3) If a variable points to object x, mark it
4) Delete all unmarked resources
5) Reorganize data to eliminate memory fragmentation

In short, in order to determine whether object x has been deleted, you'd need a reference to object x. If any reference to object x exists, the garbage collector leaves it alone. It makes a paradox.

You'll just have to trust that at some point it will be deleted. That's one drawback to GC.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!