gc does not guarantee garbage collection. It's more like yield().normally, gc algorithm will run smartly, you can't be smarter than it. but it won't cause any problem except you'll end up with useless System.gc() everywhere.
2,要注意不要过多的相互引用 normally, if your app is complex enough, the objects will form a graph. it's not practical to attempt to avoid mutual ref. And, mordern gc is using copying gc algorithm, which, is not affected by mutual ref at all.3,要灵活的运用弱引用(WeakReference),这是最有效的手段 besides some flyweight/pool, really cannot see why weak reference is effective. normally you don't need it at all.
but it won't cause any problem except you'll end up with useless System.gc() everywhere.
有介绍Enterprise Java Performance的书。
实际在高性能的程序上,要求程序员更多,GC的机制已存在了,你只能应用它,硬调system.gc()是不管用的,关键在于
1,要注意对象的生存周期
2,要注意不要过多的相互引用
3,要灵活的运用弱引用(WeakReference),这是最有效的手段
normally, if your app is complex enough, the objects will form a graph. it's not practical to attempt to avoid mutual ref.
And, mordern gc is using copying gc algorithm, which, is not affected by mutual ref at all.3,要灵活的运用弱引用(WeakReference),这是最有效的手段
besides some flyweight/pool, really cannot see why weak reference is effective. normally you don't need it at all.