I was just wondering what a ghost reference was? Is it that you don't have to refer to a object? EDIT: Sorry, I wasn't clear, the langauge is Java, and I read it about linked lists. While reading a problem to write a LinkedQueue iterator to support the remove method. Then, you would have a ghost reference.
-
what language is this concept from? – R. Martinho Fernandes Nov 03 '09 at 18:12
-
You're going to need to provide more context - where did you come across the term 'ghost reference'? The nearest I can think of is 'Phantom Rows' in a DBMS - rows that are there at one time and gone the next, because you are not running at a high-enough isolation level (SERIALIZABLE in SQL jargon). – Jonathan Leffler Nov 03 '09 at 18:18
-
3It's like this: "Remember that movie with Patrick Swazye and Whoopie Goldberg?" – Beska Nov 03 '09 at 18:21
-
1Java has soft, weak, and phantom references. The first 2 are for developers. Phantom references involve the internals of GC. Do you mean any of these? – Michael Easter Nov 03 '09 at 19:31
-
yes! That is what i was trying to understand. – Roxy Nov 03 '09 at 19:50
4 Answers
I'm not sure if this is the same, but I think you might mean a weak reference.
Weak references are used in languages that have garbage collection to have a reference to an object without blocking the garbage collection from deleting the object if no non-weak references exist.
Different languages have different semantics for this functionality. Java defines soft, weak and phantom references, each with slightly different mechanics.
This is useful in many situations. For example, on the Blackberry, you can define a Listener object that listens for system events (such as a call coming in). When you register your listener with the system, it keeps a weak reference to it. That way, when all other references to that object go away (such as when the application shuts down), the weak reference no longer points to the listener and the memory is for that listener is freed without the programmer having to remember to unregister it.

- 68,394
- 30
- 171
- 212
-
Worth a try - until we have more information on what the subject area is, it is going to be hard to tell. – Jonathan Leffler Nov 03 '09 at 18:19
As I stated in the comment, I don't know of a ghost reference, but this article has a nice write-up on the various weak references (weak, soft, and phantom). It even mentions the ReferenceQueue
issue, though I must say that I hadn't heard that before.

- 23,733
- 7
- 76
- 107
GhostReference
the most recent concept that I know is PhantomReference
, if you want to know it, by my experience, you should understand Strong reference
then weak reference
then soft reference
. after these knowledge, you might more easily to understand PhantomReference
.
In short word, these reference just help garbarge collector works more properly. (It means some times, you don't need to know these concepts and you program still run ... in short time)

- 29,632
- 51
- 171
- 250