开发者

Java garbage collector

IS there a way to set a garbage collector only for one type, like in Objective C when you do [Oppsie release]; Or is there a similar way in Java. I was thin开发者_Go百科king for setting Oppsie to null but I don't think it's similar to release.

Any suggestions?


Once you set Oppsie to null and is no longer reachable by any other reference, Java will set it as unreachable and mark it for garbage collection. You will no longer be able to reference it and Java will eventually GC it.


If this is a Java question then the answer is: DO NOT WORRY ABOUT GARBAGE COLLECTION!

Make sure that Objects that you no longer need are not referenced by any live variable and you're good! If you get any GC related exception 99% of the time you have the chance to fix it by optimizing your code. Again, don't invoke garbage collection and don't worry about that.


I am not sure what you mean by setting a garbage collector to null only for one type. What you are suggestion (by setting Oppsie to null) is setting an INSTANCE to null, nothing to do with types...

The short answer is No anyway, you cant set the garbage collector for "one type" if you mean a class or something like that by it. Once an object has no references made to it it'll be automatically marked for GC. You can suggest to java to trigger GC, but it is not guaranteed to happen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜