java - garbage collector doubts -


i have question on here regarding java garbage collector. first let me clear have understood regarding java gc. gc background thread run in background when jvm starts. each object having 1 finalize() method. method used release system resources before object destroyed. according java experts, should not put resources under finalize() method releasing system resources. becuase cannot make sure when gc run. can request gc run calling system.gc().

so question is, gc background thread run in background. how can dont know when gc run? statement "we dont know when gc call finalize() method " meaning of that? if meant, job of gc? gc's responsibility find out un used variable , remove memory. in case,why gc cannot call finalize() method also?

now how can dont know when gc run?.

functioning of gc dealt complex algos, dependent on underlying os , hardware. can't because if 1 tell particular jvm version not valid other jvms. better can't rely on that.

what job of gc.

gc finds reference less objects (read type of ref. more) , reclaims memory used them.

n case,why gc cannot call finalize() method also?

so that's sure finalize method called it's not sure when. because evenif know in jvm when finalize() method run, never know when in other jvms. so, if deal expensive resources in finalize method, programe may crash in other jvms.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -