Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Weak references - I must be missing something...

Reply
Thread Tools

Weak references - I must be missing something...

 
 
Phillip Lord
Guest
Posts: n/a
 
      03-02-2004
>>>>> "Mike" == Mike Schilling <(E-Mail Removed)> writes:

Mike> "xarax" <(E-Mail Removed)> wrote in message
Mike> newsG11c.17758$(E-Mail Removed) link.net...
>> "Mike Schilling" <(E-Mail Removed)> wrote in message
>> news:_tO0c.18886$(E-Mail Removed) om...
>> >

>> /snip/
>> > The fact that memMap is a WeakHashMap means that it won't keep
>> > otherwise unreferenced CientLargeObjects in

Mike> memory.
>> > We keep a hard reference to the LargeObject until it's safely
>> > written to disk. The fact that WeakReference can be subclassed
>> > allows us to see

Mike> the
>> > key (LargeObjectID) even after the ClientLargeObject has been
>> > collected.

>>
>> A WeakHashMap uses a WeakReference for the *KEYS*, not the
>> values.


Mike> Drat; I should know better than to write about something
Mike> without trying it.


It's very easy to have a HashMap for the values...you just stick the
values into a Reference when you put them, and take them out again
when you finish. It's like storing primitive types as values, except
using Reference objects rather than Integer or whatever.

The point with the WeakHashMap is that you have to be cleverer,
because you need to remove keys (and their values) which have been
GC'd.

I guess every time a get is called on the Map the WeakHashMap it
checks its reference queue are removes those objects.

Phil
 
Reply With Quote
 
 
 
 
Mike Schilling
Guest
Posts: n/a
 
      03-03-2004

"Phillip Lord" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

>
> It's very easy to have a HashMap for the values...you just stick the
> values into a Reference when you put them, and take them out again
> when you finish. It's like storing primitive types as values, except
> using Reference objects rather than Integer or whatever.
>
> The point with the WeakHashMap is that you have to be cleverer,
> because you need to remove keys (and their values) which have been
> GC'd.
>
> I guess every time a get is called on the Map the WeakHashMap it
> checks its reference queue are removes those objects.


That's how I'd do it. Every so often I wish for something like a
WeakHashMap on .NET, which doesn't have one, but I don't build it because I
can't decide on an algorithm that doesn't require a ReferenceQueue (which
..NET also lacks.)

(I suppose one could search all the hash chains for dead references every N
gets, or search the current hash chain every get, or search every hash chain
after the map grows by N% since the last full search or... )


 
Reply With Quote
 
 
 
 
Chris Uppal
Guest
Posts: n/a
 
      03-03-2004
Mike Schilling wrote:

> How about this: get rid of memMap and create ClientLargeObjects freely.
> Reference count LargeObjects, and persist them when their *last*
> ClientLargeObject is enqueued.


I may be misreading the OP, but I think that part of the requirement is that:

1 create LargeObject
2 use LargeObject
3 drop LargeObject

should not write LargeObject to disk *unless* the space is required sometime
during (2).

And I may be misunderstanding you, or missing the obvious, but I don't see how
these proposals meet that part of the "spec".

-- chris


 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      03-03-2004

"Chris Uppal" <(E-Mail Removed)-THIS.org> wrote in message
news:4045b6c4$0$1159$(E-Mail Removed). ..
> Mike Schilling wrote:
>
> > How about this: get rid of memMap and create ClientLargeObjects freely.
> > Reference count LargeObjects, and persist them when their *last*
> > ClientLargeObject is enqueued.

>
> I may be misreading the OP, but I think that part of the requirement is

that:
>
> 1 create LargeObject
> 2 use LargeObject
> 3 drop LargeObject
>
> should not write LargeObject to disk *unless* the space is required

sometime
> during (2).
>
> And I may be misunderstanding you, or missing the obvious, but I don't see

how
> these proposals meet that part of the "spec".


I was trying to address "How do I use weak references to detect that an
object is no longer referenced without losing the information in that
object?" I expect that's not a complete solution to the OP's problem, but
it's a start.


 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      03-03-2004
Mike Schilling wrote:

> I was trying to address "How do I use weak references to detect that an
> object is no longer referenced without losing the information in that
> object?" I expect that's not a complete solution to the OP's problem, but
> it's a start.


Fair enough.

BTW, did *anyone* see my attempt at this problem posted 2004/03/02 ? If not
then I'm going to be even more miffed about my ISP's (Nildram) increasingly
crap NNTP service than I already am.

-- chris


 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      03-05-2004

"Chris Uppal" <(E-Mail Removed)-THIS.org> wrote in message
news:(E-Mail Removed)...
> Mike Schilling wrote:
>
> > I was trying to address "How do I use weak references to detect that an
> > object is no longer referenced without losing the information in that
> > object?" I expect that's not a complete solution to the OP's problem,

but
> > it's a start.

>
> Fair enough.
>
> BTW, did *anyone* see my attempt at this problem posted 2004/03/02 ? If

not
> then I'm going to be even more miffed about my ISP's (Nildram)

increasingly
> crap NNTP service than I already am.


I saw it.

A good way to tell if a posting made it into the world is to check Google
Groups.


 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      03-05-2004
Mike Schilling wrote:

> > BTW, did *anyone* see my attempt at this problem posted 2004/03/02 ?
> > If not then I'm going to be even more miffed about my ISP's (Nildram)
> > increasingly crap NNTP service than I already am.

>
> I saw it.


Ta.

-- chris



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Weak/Soft references? Tegiri Nenashi Java 64 07-22-2008 02:52 PM
Can I convert Weak references to "hard" references ? Lars Willich Java 13 10-23-2007 07:49 PM
Problem with weak references on OS X 10.3 Caleb Clausen Ruby 7 02-06-2006 05:28 AM
What are Weak Unknown, Weak Zero and Weak 1? Kuan Zhou VHDL 1 01-24-2005 12:57 PM
Strange behavior with weak references Nicholas Zigarovich Java 0 09-02-2003 08:42 PM



Advertisments