Topic: Soft reference in java |
Print this page |
1.Soft reference in java | Copy to clipboard |
Posted by: zyzhang Posted on: 2003-11-04 17:51 I am designing a factory class to create objects which is only availible at runtime(or just uncompiled generated source codes), I use the Class.forName() to load it and instantiated at runtime.It's said that this is a kind of soft reference. Can anyone give me some advice on the drawbacks of this implementation? I have not found a better way to solve this kind of problem(do not reference object at compile time,and pass the compiler check.) |
2.Re:Soft reference in java [Re: zyzhang] | Copy to clipboard |
Posted by: java8964 Posted on: 2003-11-05 01:25 No. This is not a soft reference. It is just create objects at runtime. For java, there is no difference between you create an object using new or Class.forName(). It gives you the flexibility to create an object on the fly. The class name can be loaded at run time from a properties file or other source. The drawback is only that the source code of that class is not available at compile time. That is it. The softly reachable state manifests itself in Java through the SoftReference class. When you initialize a SoftReference object, you store a reference to a referent in that object. The object contains a soft reference to the referent, and the referent is softly reachable if there are no other references, apart from soft references, to that referent. If heap memory is running low, the garbage collector can find the oldest softly reachable objects and clear their soft references -- by calling SoftReference's inherited clear() method. Assuming there are no other references to those referents, the referents enter the resurrectable state (if they contain overridden finalize() methods) or the unreachable state (if they lack overridden finalize() methods). Assuming the referents enter the resurrectable state, the garbage collector calls their finalize() methods. If those methods do not make the referents reachable, the referents become unreachable. The garbage collector can then reclaim their memory. |
3.Re:Soft reference in java [Re: zyzhang] | Copy to clipboard |
Posted by: zyzhang Posted on: 2003-11-05 18:10 Thanks for your explanation. I think i can use softreference(a kind of weak reference) in my hash map caching implementation. |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |