You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Rhett Aultman <Ra...@fcci-group.com> on 2002/11/07 14:58:31 UTC

References (WAS:RE: HashMaps)

I wasn't suggesting using them because they're sexy.  Personally, I don't use Reference objects unless they can't be avoided.  However, collections that use WeakReferences can be a serious help.  Essentially, they can help ensure object cleanup in a more timely fashion than traditional techniques, as an object placed in, say, a WeakHashMap will automatically be garbage collected when the only reference to the object is in the WeakHashMap.  It's a natural safeguard against someone forgetting to dereference an object in a Collection when they're done with it, which results in memory leakage.

Again, not being a FOP code veteran, I don't know where the points of use might be, but Reference objects and the "weak collections" seem to be a part of the Java API that don't get much coverage, so I wasn't sure if anyone had even considered their use.

-----Original Message-----
From: Jeremias Maerki [mailto:dev.jeremias@greenmail.ch]
Sent: Thursday, November 07, 2002 8:51 AM
To: fop-dev@xml.apache.org
Subject: Re: HashMaps (WAS:RE: interface instead of implementation)


I didn't intend to kill that discussion with my response. I'm not a
specialist on those Reference classes but I've heard enough to say that
it can be tricky and should probably not be used just because it's sexy.
I'd vote for not using them unless there is a real good reason. I'm not
sure about your use case, but you might just have to do some research.
I'm sorry not to be more of a help.

Here's one URL describing the stuff in short. I'm sure there are better
ones.
http://developer.java.sun.com/developer/TechTips/1999/tt0511.html#tip2

On Thu, 07 Nov 2002 09:54:51 +1000 Peter B. West wrote:
> I was hoping there might be a little more detailed discussion here.  I 
> have no experience of WeakHashMaps or the various Reference objects, but 
> I have been thinking about using Reference objects, rather than direct 
> references, to point to the Nodes in my Tree, with the idea that at 
> least the first iteration in a cache/retrieve cycle on a subtree could 
> be handled transparently within the Tree.


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org


Re: References (WAS:RE: HashMaps)

Posted by Keiron Liddle <ke...@aftexsw.com>.
On Thu, 2002-11-07 at 14:58, Rhett Aultman wrote:
> I wasn't suggesting using them because they're sexy.  Personally, I don't use Reference objects unless they can't be avoided.  However, collections that use WeakReferences can be a serious help.  Essentially, they can help ensure object cleanup in a more timely fashion than traditional techniques, as an object placed in, say, a WeakHashMap will automatically be garbage collected when the only reference to the object is in the WeakHashMap.  It's a natural safeguard against someone forgetting to dereference an object in a Collection when they're done with it, which results in memory leakage.

The image caching actually uses the WeakHashMap in cvs.
The idea is that during the creation of a document the image will be
load then at some later time output. During this time it has a strong
reference. Once the image is no longer needed by the renderer then it is
placed into a weak hashmap, this may garbage collect if memory is needed
(although I read somewhere that the jvm often gc's first time).
If another document then needs the image it is recovered if available
and strongly referenced until finished with that document.

As for other parts of FOP, I haven't thought of any, usually it is a
case of it is needed or not needed.

> Again, not being a FOP code veteran, I don't know where the points of use might be, but Reference objects and the "weak collections" seem to be a part of the Java API that don't get much coverage, so I wasn't sure if anyone had even considered their use.
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org