Can I convert Weak references to "hard" references ?
14 Message(s) by 11 Author(s) originally posted in java help
| From: LarsWill |
Date: Sunday, October 21, 2007
|
I have problems because of JAVA
crash es after garbage collection of weak
reference d
object s.
Can I somehow:
a) Convert weak references into hard references ?
b) at least get a notication when a weak referenced object is garbage collected ?
Lars
| From: Roedy Green |
Date: Sunday, October 21, 2007
|
wrote in
message ,
quoted or indirectly quoted someone who said :
a) Convert weak references into hard references ?
you'd just add a hard reference to the object.
--
Roedy
Green Canadian Mind Products
The JAVA Glossary
http://mindprod.com
| From: Lew |
Date: Sunday, October 21, 2007
|
wrote in message:
I have problems because of JAVA crashes after garbage collection of weak
referenced objects.
What is the
nature of these crashes? Is it because you are not guarding
against the consequences of reaping WeakReferences after they've been garbage
collected?
Crashes like that do not "just happen"; there's a reason and it's in your code.
--
Lew
| From: Hunter Gratzner |
Date: Sunday, October 21, 2007
|
wrote in message:
wrote in message:
Crashes like that do not "just happen"; there's a reason and it's in your code.
There is also a chance it is in Sun's code, e.g. in the JAVA or native
code of the VM. VM crashes are rare but do happen.
To the OP: Post the
complete original
error message. Do not paraphrase,
use copy-paste. Do not forget to tell us the JAVA
version and your OS,
too.
| From: Lew |
Date: Sunday, October 21, 2007
|
wrote in message:
Crashes like that do not "just happen"; there's a reason and it's in your code.
wrote in message:
There is also a chance it is in Sun's code, e.g. in the JAVA or native
code of the VM. VM crashes are rare but do happen.
I assumed the OP at least was accurate to the extent of the description given.
If their error message hadn'thing to do with weak references, of course,
you're right. If the crash is directly related to the use of weak references,
then I stand by my assessment. I should've done what you did, ask for the
actual facts before rendering judgment.
FWIW, there are no active weak-reference-related VM-crashing bugs listed at Sun.
To the OP: Post the complete original error message. Do not paraphrase,
use copy-paste. Do not forget to tell us the JAVA version and your OS,
too.
--
Lew
| From: Lew |
Date: Sunday, October 21, 2007
|
wrote in message:
I have problems because of JAVA crashes after garbage collection of weak
referenced objects.
...
b) at least get a notication when a weak referenced object is garbage
collected ?
wrote in message:
Object strong = weak.get();
if (strong != null )
{
// store the strong reference somewhere if you do not want
// it to be garbage collected.
}
else
{
// You're out of luck - the weakref has already been
// collected
}
http://JAVA.sun.com/j2se/1.5.0/docs/api/JAVA/lang/ref/ReferenceQueue.html
might do what you want.
There, he's given you two different approaches.
--
Lew
| From: bcd |
Date: Sunday, October 21, 2007
|
In article
<471b34cf$0$27140$9b4e6d93@xxxxxxxxxxx>,
wrote in message:
I have problems because of JAVA crashes after garbage collection of weak
referenced objects.
Can I somehow:
a) Convert weak references into hard references ?
WeakReference weak = ...;
...
Object strong = weak.get();
if (strong != null)
{
// store the strong reference somewhere if you do not want
// it to be garbage collected.
}
else
{
// You're out of luck - the weakref has already been
// collected
}
b) at least get a notication when a weak referenced object is garbage
collected ?
http://JAVA.sun.com/j2se/1.5.0/docs/api/JAVA/lang/ref/ReferenceQueue.html
might do what you want.
Cheers,
Bent D
--
Bent Dalager - bcd@xxxxxxxxxxx -
http://www.pvv.org/~bcd
powered by emacs
| From: Mark Space |
Date: Sunday, October 21, 2007
|
wrote in message:
a) Convert weak references into hard references ?
I have not actually tried this, but I think it'd work
Given some WeakReference wf:
Object hardRef = wf;
if( hardRef == null )
// Reload the resource
;
ZZZ zzz = (ZZZ) hardRef; // Need to cast to use it...
| From: Daniel Pitts |
Date: Sunday, October 21, 2007
|
wrote in message:
wrote in message:
a) Convert weak references into hard references ?
I have not actually tried this, but I think it'd work
Given some WeakReference wf:
Object hardRef = wf;
if( hardRef == null )
// Reload the resource
;
ZZZ zzz = (ZZZ) hardRef; // Need to cast to use it...
That does not work.
Although, I think the OP incorrectly described his problem. If he has a
problem with WeakReference, its most likely his own use of it that is
wrong. He needs to show us the exact error.
--
Daniel Pitts' Tech Blog:
<http://virtualinfinity.net/wordpress/>
| From: Hendrik Maryns |
Date: Monday, October 22, 2007
|
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigC58ED0601B8FFD5DF0EBCB61
Lars Willich schreef:
I have problems because of JAVA crashes after garbage collection of wea=
k referenced objects.
=20
Can I somehow:
=20
a) Convert weak references into hard references ?
By subclassing WeakReference and including a
real reference to the
object in it. Depends on what you want to do, of course.
b) at least get a notication when a weak referenced object is garbage c=
ollected ?
Write a finaliser for your subclass.
H.
--=20
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html--------------enigC58ED0601B8FFD5DF0EBCB61
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN
PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE -
http://enigmail.mozdev.org
iD8DBQFHHIM5e+7xMGD3itQRAjQhAJwOlyr+ZiFBMRtY3uAPB+TXT5MvDwCbBviY
KbGTRcDLuImEL9ymxK5y06Q=
=eZZC
-----END PGP SIGNATURE-----
--------------enigC58ED0601B8FFD5DF0EBCB61--
| From: Christopher Benson-Manica |
Date: Monday, October 22, 2007
|
wrote in message:
Lars Willich schreef:
a) Convert weak references into hard references ?
By subclassing WeakReference and including a real reference to the
object in it. Depends on what you want to do, of course.
Making a WeakReference actually behave as a "strong" reference strikes
me as a bad plan.
b) at least get a notication when a weak referenced object is garbage collected ?
Write a finaliser for your subclass.
Won't work. The referent won't be garbage collected unless the real
reference is cleared, and then you're back to a WeakReference.
--
C. Benson Manica | I appreciate all corrections, polite or otherwise.
cbmanica(at)gmail.com |
----------------------| I don't currently read any posts posted through
sdf.lonestar.org |
Google groups, due to rampant unchecked spam.
| From: bcd |
Date: Monday, October 22, 2007
|
In article
<ffhvvh$2fk$1@xxxxxxxxxxx>,
wrote in message:
-=-=-=-=-=-
Lars Willich schreef:
b) at least get a notication when a weak referenced object is garbage collected ?
Write a finaliser for your subclass.
This is not really recommended as it may (I have a feeling that it
/will/) cause the garbage collector to
handle those objects in a
completely different manner than it otherwise would've, and it is
likely to degrade the performance of the collector.
Cheers,
Bent D
--
Bent Dalager - bcd@xxxxxxxxxxx -
http://www.pvv.org/~bcd
powered by emacs
| From: Ingo R. Homann |
Date: Tuesday, October 23, 2007
|
Hi,
concerning the API-doku:
wrote in message:
I have problems because of JAVA crashes after garbage collection of weak referenced objects.
Can I somehow:
a) Convert weak references into hard references ?
Yes:
T hardRef=weakRef.get();
b) at least get a notication when a weak referenced object is garbage collected ?
Yes:
IIRC, the
class ReferenceQueue is designed for that case.
Overriding the finalize-method should work as well. (Note that
finalizers are often declared as buggy,
deprecated and unsafe, but work
perfectly in practise.)
Ciao,
Ingo
| From: Ian Shef |
Date: Tuesday, October 23, 2007
|
wrote in message in
I have problems because of JAVA crashes after garbage collection of weak
referenced objects.
Can I somehow:
a) Convert weak references into hard references ?
b) at least get a notication when a weak referenced object is garbage
collected ?
Lars
Does not get() (inherited from JAVA.lang.ref.Reference) provide these?
get() returns the hard reference, or returns null if the referenced object
has been cleared (not necessarily garbage collected yet).
Are you sure that this is really the problem, and are you sure that this is
the right
solution to your problem? If you've weak referenced objects,
then is not there an expectation that they'll be garbage collected? If you
are going to turn weak references into hard references, why have the weak
references in the first place?
--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Next Message: Filtering data from a file
Blogs related to Can I convert Weak references to "hard" references ?
Comprehensive news articles from the magazine. Updated daily.
myspace encouragement comments for men.
fence designs how do i find the value of stock certificates how does beano work gmc van interior storage Digital mp4 player with fm carlton cohen university of florida free monthly calendars 92
...
Featuring almost everything from new and used products.
922 033 96 68 9230837675 58 weii ato tax rates au the process of diamond mining from the raw material to the finished goods eureferendum blog
java 64 bit no drag and drop
hard core girl on girl porn australian designers interfaith
...
The official Magazine Website.
picket
fences tv show arc ut haven marie pans san elijo lagoon henrico county, va port 8080 tomcat spr22 drive Training strategy consultancy uk thanks to my mother veneer plywood www.thebowesmuseum.org.uk rentals sicily windshield
...
Welcome to the Subscription Center.
downloading all the english and american texts even the woodpecker owes his hemp fabric billingham bag leah griffith hour detroit magazine 1212140979.jpg holyoke mall hours swimming pool
fencing cars for under $25000.00 body found near
...
Official site featuring a complete catalog.
Mexico: history of serenading. erotic comics hostile fucker. stress reaction feel forgiveness good listening
convert horsepower to watts variable speed cd player victoria by the sea pei accomodations restraint life of rev sun myung moon
...
Bangkok, Cambodia, Laos 2006 - 2007
They simply marched everyone out of town, killing the
weak and the stragglers. And, had I survived, I would be old, from years of starvation and, when I got lucky, a life of
hard work. No dental work to preserve my teeth.
...